Sponsored Content
Top Forums Shell Programming and Scripting What is the meaning of this regular expression? Post 302601912 by agama on Friday 24th of February 2012 09:48:46 PM
Old 02-24-2012
Code:
^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])((\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$



There are 4 major sections. The red '^' at the beginning 'anchors' the pattern to the beginning of the data. The expression will only evaluate to true if the first character of the pattern is the first character of the data.

The red '$' at the end is also an anchor which anchors the match to the end of the data. The expression will evaluate to true only if the last character of the matched string is the last character of the data.

There are two major sections in between (blue and black). The blue section consists of a group which is contained within parens. Within the group are pipe '|' separated fields; the pipe indicates an OR condition such that the pattern is considered a match when any single field's expression is true.

The blue group contains a set of 4 fields which will evaluate to true when the chararacters at the beginning
of the string match:

Code:
 [1-9]           one number 0-9
OR
 [1-9][0-9]     two numbers one number in the set 1-9 followed by a number in the set 0-9
OR
 1[0-9][0-9]    three numbers 1 followed by a number in the set 0-9 followed by a number in the set 0-9
OR
 2[0-4][0-9]    three numbers 2 followed by a number in the set 0-4 followed by a number in the set 0-9
OR
  25[0-5]        three numbers 2 then 5 followed by a number in the set 0-5



The second section (black) contains a nested group. The inner group is similar to the blue group. The first number is allowed to be 0 even if a single digit, and the set of up to three digits must be preceded with a dot. There is a backslant (\) in front of the dot because the dot has special meaning and to indicate that a true (real) dot is to be matched it must be escaped.

The outer set of parens in the second group is followed by {3} which is a repetition operator that affects the adjacent group. The 3 indicates that this pattern must exist exactly three times.

I haven't completely vetted it, but it appears that the intent is to match an IP address.
These 2 Users Gave Thanks to agama For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regular Expression + Aritmetical Expression

Is it possible to combine a regular expression with a aritmetical expression? For example, taking a 8-numbers caracter sequece and casting each output of a grep, comparing to a constant. THX! (2 Replies)
Discussion started by: Z0mby
2 Replies

2. UNIX for Dummies Questions & Answers

Need help in Regular Expression

I have a file with data that looks like - record nullable { final_delim=end ,delim="~%%~" ,quote=none } ( 1_UPC:string; 2_QUANTITY:string; ) I want to fetch the first column that starts with integer. e.g - 1_UPC, 2_QUANTITY. I tried "awk -F ":" -v var1="^0-9" '$1==var1' inschemafile".... (2 Replies)
Discussion started by: mahabunta
2 Replies

3. Programming

help in regular expression

Hi all, I'm working with flex (version 2.5.4a) on GNU/linux. I need to frame a regular expression which would match cases where word "file" does not occur. Negated character class wont work for me because they enforce "or" clause between different chars (so something like wont work). I would like... (5 Replies)
Discussion started by: Rakesh Ranjan
5 Replies

4. Linux

Regular expression to extract "y" from "abc/x.y.z" .... i need regular expression

Regular expression to extract "y" from "abc/x.y.z" (2 Replies)
Discussion started by: rag84dec
2 Replies

5. Shell Programming and Scripting

regular expression (.*?)

hi all, i have a text file with below content ............................... ............................... ............................... ............................... %%Page: (4) 4 %%PageBoundingBox: 34 -30 584 831 %%BeginPageSetup %%BeginFeature: *PageSize A4 595 842... (7 Replies)
Discussion started by: uttamhoode
7 Replies

6. Shell Programming and Scripting

Integer expression expected: with regular expression

CA_RELEASE has a value of 6. I need to check if that this is a numeric value. if not error. source $CA_VERSION_DATA if * ] then echo "CA_RELESE $CA_RELEASE is invalid" exit -1 fi + source /etc/ncgl/ca_version_data ++ CA_PRODUCT_ID=samxts ++ CA_RELEASE=6 ++ CA_WEEK_NO=7 ++... (3 Replies)
Discussion started by: ketkee1985
3 Replies

7. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

8. UNIX for Dummies Questions & Answers

What is the meaning of this awk expression using sub?

Cannot understand what the "&" in the sub expression is supposed to do. {sub(/^/,"&" s)} (3 Replies)
Discussion started by: kristinu
3 Replies

9. UNIX for Advanced & Expert Users

sed: -e expression #1, char 0: no previous regular expression

Hello All, I'm trying to extract the lines between two consecutive elements of an array from a file. My array looks like: problem_arr=(PRS111 PRS213 PRS234) j=0 while } ] do k=`expr $j + 1` sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt ---some operation goes... (11 Replies)
Discussion started by: InduInduIndu
11 Replies

10. UNIX for Dummies Questions & Answers

Regular expression help

Hi, I am quite knew to scripting and I am trying to get a regular expression to work to check that a user enters a valid version number such as 1 or 1.1 or 12.3 etc. I dont seem to be able to get it to work as it picks up versions such as 1.......2. I only want it to work with a single dot.... (12 Replies)
Discussion started by: frodo61
12 Replies
RBASH(1)						      General Commands Manual							  RBASH(1)

NAME
rbash - restricted bash, see bash(1) RESTRICTED SHELL
If bash is started with the name rbash, or the -r option is supplied at invocation, the shell becomes restricted. A restricted shell is used to set up an environment more controlled than the standard shell. It behaves identically to bash with the exception that the follow- ing are disallowed or not performed: o changing directories with cd o setting or unsetting the values of SHELL, PATH, ENV, or BASH_ENV o specifying command names containing / o specifying a file name containing a / as an argument to the . builtin command o specifying a filename containing a slash as an argument to the -p option to the hash builtin command o importing function definitions from the shell environment at startup o parsing the value of SHELLOPTS from the shell environment at startup o redirecting output using the >, >|, <>, >&, &>, and >> redirection operators o using the exec builtin command to replace the shell with another command o adding or deleting builtin commands with the -f and -d options to the enable builtin command o using the enable builtin command to enable disabled shell builtins o specifying the -p option to the command builtin command o turning off restricted mode with set +r or set +o restricted. These restrictions are enforced after any startup files are read. When a command that is found to be a shell script is executed, rbash turns off any restrictions in the shell spawned to execute the script. SEE ALSO
bash(1) GNU Bash-4.0 2004 Apr 20 RBASH(1)
All times are GMT -4. The time now is 09:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy