Munro.humber.ca
Pattern MatchingShell ExpressionsIn the shell you can use the following to match file namesExampleMeaning????matches a single charactermatches 3 characters*matches any number of characters[abcxyz][a-rS-Z5-9P]matches any characters inside [] or a range of characters[^abcxyz123][!abcxyz1-9]Matches anything but the characters [] or a range of character! and ^ only have this meaning if they after the first character[[:alpha:]]matches a character class. See Extended Regular expressions{Jan,Feb,March,Oct}{report10..20}Look for all of the alternate valuesor the entire range of values~~smithmatch your home directoryor the directory of another userExtended Regular Expressions (Extended regex)Regular expressions were developed after shell expressions, and were designed to handle more complex patterns needed to search inside text and binary files.ExampleMeaning. (dot)Matches a single character^Matches the beginning of a line$Matches the end of a line[abcxyz123][a-rS-Z5-9P]Matches any of the characters inside [] or a range of charactersImportant note: If you insert a comma in the list, it isn’t a separator – it will litterally match a comma. Also if you want to match a - (dash), you need to escape it with a backslash: \-[^abcxyz123][!abcxyz1-9]Matches anything but the characters [] or a range of character! and ^ only have this meaning if they after the first character[[:alpha:]][[:digit]][:alum:][:blank:][:cntrl:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]character classes - must be inside square brackets. Example matches A9 – alphabetic letter + digit.Other classes:alphanumericspace or tabcontrol characterprintable, except for spacelowercaseprintable including spacepunctuation onlywhitespace character including form feet, carriage return, vertical and horiz. tabsuppercasehexadecimal digit(pattern1|pattern2)A string of characters – the | means “or” - either string or pattern can match(pattern){3}Exactly 3 of a letter or a pattern.{10}$ - lines with 10 characters before the end[[:digit:]]{5} - 5 digits(pattern){3,5}3 to 5 copies of a pattern - the match is greedy – it finds the longest match(pattern){3,}3 or more copies of a letter or a pattern(pattern)*Any number (including 0) copies of a pattern(pattern)+Match 1 or more – the match is greedy[0-9]*9(pattern)?Match 0 or 1 , but not more than one copy of a pattern[0-9]?9 - matches digits followed by a 9 or 9 by itself. <match the beginning of a word - >match the end of a word\nBack reference. Match the nth bracketted expression again(TECH154|TECH152).*\1 - match the 1st result again later in the lineThe textbook doesn’t discuss the extended regex, only basic regex. The extended version is easier to use. The differences are as follows: In basic regex the special characters () {} <> and | have to be preceded by a backslash (the escape character). This often makes regex harder to read. In extended regex you just type them in, but if you want to match them as an actual character, you need to put a backslash in front. Basic regex also doesn’t support + or ? Commands that use basic regex: expr, grep, vimCommands that use extended regex: egrep, sed -e , awk, perl, python, oracle, javaThere can be slight differences in behaviour and notation in how regex has been implemented in each of these tools – neither regex nor extended regex has ever been standardized.In vim the default when you use / or ? to search is basic regex. You can switch to extended regex known as “magic” mode by immediately following the search operator with \v (backslash v) ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- regular expressions umd
- introduction to tregex
- regular expressions in jlex edu
- lecture 18 theory of computation regular expressions and
- cs351 intro to unix java regular expressions
- jflex regular expressions
- java regular expressions
- regular expressions the complete tutorial
- microsoft visual studio
- george mason university
Related searches
- ca dept of education website
- ca dept of education jobs
- globalresearch ca articles
- globalresearch.ca latest news
- ca real estate license search
- ca dept of tax
- ca wage and hour laws 2019
- ca teacher credential lookup
- ca water distribution classes
- ca community college free
- globalresearch ca global research
- globalresearch ca org