View previous topic :: View next topic |
Author |
Message |
blakelyb
Joined: 22 Dec 2007 Posts: 2
|
Posted: Sat Dec 22, 2007 11:22 pm Post subject: ignore case |
|
|
One regex site said the /i switch was to ignroe case. But it does not seem to work in PFrank. Is it supposed to work if done right?
Otherwise i just put every letter in bracks with its lower and upper case. Like [Ll][Ii][Kk][Ee] this. |
|
Back to top |
|
|
admin Site Admin
Joined: 09 Mar 2007 Posts: 448 Location: Canada
|
Posted: Sun Dec 23, 2007 9:06 pm Post subject: |
|
|
The syntax for ignoring letter case using the python style regex (and other styles) is to add the following flag at the start of the regular expression:
(?i)
Your method will work too but it becomes cumbersome to type all double letters and enclose them in square brackets. Instead use:
'(?i)like'
The above will match the word 'like' in all letter cases.
Other flags are also available; these are described in the built-in help (just search for 'flag'.
Peter. |
|
Back to top |
|
|
blakelyb
Joined: 22 Dec 2007 Posts: 2
|
Posted: Sat Dec 29, 2007 7:42 am Post subject: |
|
|
Thanks for the fast help for my question. Now I see I need a parenthesis and a question mark. Before I had tried a slash, like in DOS command switch - wrong.
In the Custom renaming "Search Pattern" box, I tried your suggestion and had to play with it a bit to finally come up with the following, which worked:
(?xi) \[FLAC]
to find [FLAC], or [Flac], or [flac], etc. I wanted the brackets to be searced like regular text. I do not understand what the "?" or the "x" does, but it worked. |
|
Back to top |
|
|
admin Site Admin
Joined: 09 Mar 2007 Posts: 448 Location: Canada
|
Posted: Sun Dec 30, 2007 7:38 am Post subject: |
|
|
The '(?' syntax is used to indicate the start of a special sequence. If the next characters are alphabetic, then those characters are interpreted as flags. e.g.
(?i) specifies the 'i' flag which indicates to 'ignore case' in the regular expression that follows.
When you use a regex flag you have to be careful with your whitespace because if you add a blank after the flag sequence then that blank is the first character that is going to be matched in your expression.
If you want to use whitespace to make the regex look clearer but not be included in the regular expression then you can use the 'x' flag. The 'x' flag causes whitespace in the expression to be ignored unless it is escaped or enclosed in square brackets.
e.g.
(?i) string1
matches: ' string1' or ' STRing1'
Using '(ix) specifies both the 'i' and 'x' flags.
Therefore:
(?ix) string1
matches: 'string1' or 'STRing1'
I'm surprised that your expression worked because you did not escape the closing square bracket with a backslash.
I would have used:
(?xi) \[FLAC\] # notice the blank after the '(?i)'
or
(?xi) \[FLAC\]
or if you don't use the 'x' flag then the expression would have to be:
(?xi)\[FLAC\]
Hope that clarifies things.
Peter. |
|
Back to top |
|
|
|