Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Syntax of the regular expressions
Gery
Anybody knows where I get a documentation about syntax of the regular expressions (_regex of iw.cfg).
I don't understand the symbol $ or $1 or ^ in a regex, I supose that are variables, but where I define it.
Are regular expressions a standard syntax?
Thanks for the help.
Find more posts tagged with
Comments
Jeremy
Hi,
There is information in the admin guide. I think you should probably get a book on Regular Expressions to help you out. O'Reilly has a really good one.
$1, $2, $3 etc are all the variables of the ( ) in the first part of the statement. ^ matches from the begining of the line, or if it is with in [^ ] then it negates the match within the square brackets.
I have probably not explained it very well at all, but then I am not in the book writing industry! There are also many sites on the web that can help you with that.
HTH
Jeremy
Gery
Thanks for your help, I'll try it.
Adam Stoller
I too would recommend the O'Reilly book.
However, as a quick primer:
()
's on the left-hand-side of the statement are used to either capture data within register variables (
$1
,
$2
, ...) and/or for providing alternative patterns to match against:
_regex=^(.*)/WORKAREA/(jeremy|ghoti)/(.*)=$1/STAGING/$3
$1 = everying in the path up-to-but-not-including /WORKAREA/
$2 is unused on the right-hand side, but means that we should only match against workareas named jeremy or ghoti but it wouldn't match against a workarea named geshuar
$3 = everything in the path after the workarea name
So this would effectively translate a workarea-rooted path for two specific workareas into a staging-rooted path
$
at the end of the left-hand-side expression represents an
anchor
indicating that is the end of the string being looked at
Using a pattern like:
_regex=^(.*)/WORKAREA/ghoti$
would match against /iwmnt/default/main/WORKAREA/ghoti, but would not match against /iwmnt/default/main/WORKAREA/ghoti/foo because the string being checked did not end with the pattern-string ghoti
In the same light,
^
at the very beginning of the left-hand-side expression represents and
anchor
indicating that is the beginning of the string being looked at
Using a pattern like:
_regex=^/default/main
would mach against /default/main/WORKAREA/ghoti/foo, but would not match against /iwmnt/default/main/WORKAREA/ghoti/foo because the string being checked did not begin with the pattern-string /default
Now to add to the confusion, if you use what's called a character-class expression, which appears within square brackets (
[]
) and you put a
^
at the beginning of that, it means NOT
So _regex=^.*/default/[aj] would match against /default/main/jeremy and /iwmnt/default/main/adam, but not /iwmnt/default/main/geshuar, however, _regex=^.*/default/[^aj] would do the opposite, it would match /iwmnt/default/main/geshuar but not /default/main/jeremy nor /iwmnt/default/main/adam (this is most often used with things like /'s such as: _regex=^(.*)/WORKAEA/[^/]+/(.*)$=$1/STAGING/$2 to translate any workarea-rooted path into a staging-rooted path)
Again, reading the book would be best and also keep in mind that, unfortunately, there are many variants of regular expressions and not all of them share the same syntax - for example, most command shells accept something like
abc*
to match against
abc
,
abcc
, and
abcd
, but for something like Perl, it would match the first two but not the last one - to do that you'd need to add an additional piece of syntax (
.
) like
abc.*
.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com