Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - regular expressions - why are they so hard to compose and decipher?

Reply
 
Old 09-03-2009   #1 (permalink)
Larry__Weiss


 
 

regular expressions - why are they so hard to compose and decipher?

Except for a few concepts like anchoring the match to the beginning and ending
of a target using ^ and $ I have the hardest time internalizing the syntax of
regular expressions.

The opposite is true of wildcards. I am completely comfortable with them. I
don't know if that's because I encountered them first, or that they are so
simple that there are not combinations of characters to learn.

It all seems "learned by rote" to me. It may be the escape sequences embedded
in them that makes it seem that they are more complex that they really are.

I guess I need to learn a process of first resolving the escaped characters into
a special notation that uses one symbol per escaped character, and then seeing
what patterns emerge. I'm lost in the slashes!

I feel with regular expressions like I feel with the game of Chess. I know how
all the pieces move, and how the game is played, but have no feeling of comfort
that I play well (and plenty of experiences that prove it to be true that I play
poorly).

- Larry

My System SpecsSystem Spec
Old 09-03-2009   #2 (permalink)
Larry__Weiss


 
 

Re: regular expressions - why are they so hard to compose and decipher?

Thanks to Don Jones for this remarkably easy to follow starter on PowerShell regex

http://207.46.16.252/en-us/magazine/...owershell.aspx

I guess I missed out on some "recent" regex expansion since I've never coded
with Perl.

http://en.wikipedia.org/wiki/Regular...racter_classes

- Larry Weiss

Larry__Weiss wrote:
Quote:

> Except for a few concepts like anchoring the match to the beginning and
> ending of a target using ^ and $ I have the hardest time internalizing
> the syntax of regular expressions.
>
> The opposite is true of wildcards. I am completely comfortable with
> them. I don't know if that's because I encountered them first, or that
> they are so simple that there are not combinations of characters to learn.
>
> It all seems "learned by rote" to me. It may be the escape sequences
> embedded in them that makes it seem that they are more complex that they
> really are.
>
> I guess I need to learn a process of first resolving the escaped
> characters into a special notation that uses one symbol per escaped
> character, and then seeing what patterns emerge. I'm lost in the slashes!
>
> I feel with regular expressions like I feel with the game of Chess. I
> know how all the pieces move, and how the game is played, but have no
> feeling of comfort that I play well (and plenty of experiences that
> prove it to be true that I play poorly).
>
My System SpecsSystem Spec
Old 09-03-2009   #3 (permalink)
Larry__Weiss


 
 

Re: regular expressions - why are they so hard to compose and decipher?

Also,
http://www.johndcook.com/regex.html

is helpful to learn just how alike Perl and PowerShell are wrt regex.

- Larry

Larry__Weiss wrote:
Quote:

> Thanks to Don Jones for this remarkably easy to follow starter on
> PowerShell regex
>
> http://207.46.16.252/en-us/magazine/...owershell.aspx
>
> I guess I missed out on some "recent" regex expansion since I've never
> coded with Perl.
>
> http://en.wikipedia.org/wiki/Regular...racter_classes
>
>
>
> Larry__Weiss wrote:
Quote:

>> Except for a few concepts like anchoring the match to the beginning
>> and ending of a target using ^ and $ I have the hardest time
>> internalizing the syntax of regular expressions.
>>
>> The opposite is true of wildcards. I am completely comfortable with
>> them. I don't know if that's because I encountered them first, or
>> that they are so simple that there are not combinations of characters
>> to learn.
>>
>> It all seems "learned by rote" to me. It may be the escape sequences
>> embedded in them that makes it seem that they are more complex that
>> they really are.
>>
>> I guess I need to learn a process of first resolving the escaped
>> characters into a special notation that uses one symbol per escaped
>> character, and then seeing what patterns emerge. I'm lost in the
>> slashes!
>>
>> I feel with regular expressions like I feel with the game of Chess. I
>> know how all the pieces move, and how the game is played, but have no
>> feeling of comfort that I play well (and plenty of experiences that
>> prove it to be true that I play poorly).
>>
My System SpecsSystem Spec
Old 09-03-2009   #4 (permalink)
tojo2000


 
 

Re: regular expressions - why are they so hard to compose anddecipher?

On Sep 3, 12:56*pm, Larry__Weiss <l...@xxxxxx> wrote:
Quote:

> Thanks to Don Jones for this remarkably easy to follow starter on PowerShell regex
>
> *http://207.46.16.252/en-us/magazine/...owershell.aspx
>
> I guess I missed out on some "recent" regex expansion since I've never coded
> with Perl.
>
> * *http://en.wikipedia.org/wiki/Regular...racter_classes
>
> - Larry Weiss
>
>
>
> Larry__Weiss wrote:
Quote:

> > Except for a few concepts like anchoring the match to the beginning and
> > ending of a target using ^ and $ I have the hardest time internalizing
> > the syntax of regular expressions.
>
Quote:

> > The opposite is true of wildcards. *I am completely comfortable with
> > them. *I don't know if that's because I encountered them first, or that
> > they are so simple that there are not combinations of characters to learn.
>
Quote:

> > It all seems "learned by rote" to me. *It may be the escape sequences
> > embedded in them that makes it seem that they are more complex that they
> > really are.
>
Quote:

> > I guess I need to learn a process of first resolving the escaped
> > characters into a special notation that uses one symbol per escaped
> > character, and then seeing what patterns emerge. *I'm lost in the slashes!
>
Quote:

> > I feel with regular expressions like I feel with the game of Chess. *I
> > know how all the pieces move, and how the game is played, but have no
> > feeling of comfort that I play well (and plenty of experiences that
> > prove it to be true that I play poorly).
Regular expressions ARE more complicated than wildcards, but they can
do a whole lot more. There are more than the items listed below, like
zero-width lookahead and lookbehind assertions, but this little cheat
sheet will work for you 99% of the time.

Most regex tokens fall into one of four categories:

1. What kind of character is it?
--------------------------------

[] - Any of the characters inside the brackets will match, use the
dash to indicate a range.
Examples: [a-z] will match any letter.
[aeiou] will match any vowel
\w - "word" characters. Basically matches [a-z0-9_]
\s - "whitespace" characters. matches spaces, tabs, etc.
\d - any digit. Basically matches [0-9]
\t - a tab character
.. - any character


2. How many characters? (the below appear after the character class)
-----------------------

{x} - Matches x number of characters
{x, y} - Matches minimum x number of characters, maximum y characters
Examples: \d{4} matches 4 digits
* - Matches ZERO or more of the character (as many as possible)
+ - Matches ONE or more of the character (as many as possible)
*? - Matches ZERO or more characters (as few as possible)
+? - Matches ONE or more characters (as few as possible)


3. Where is the character?
--------------------------

\b - matches a word boundary, without actually absorbing any
characters
^ - matches the beginning of a string
$ - matches the end of a strong


4. Grouping
-----------

() - Any characters between the parentheses will be their own group.
Check $matches after using -match to see the groups.
| - A pipe character is the OR character
Example: (one|two) will match the word "one" or the word "two"
My System SpecsSystem Spec
Old 09-03-2009   #5 (permalink)
Larry__Weiss


 
 

Re: regular expressions - why are they so hard to compose anddecipher?

Super! Like those "as many as possible" and "as few as possible" descriptions.

- Larry

tojo2000 wrote:
Quote:

> Regular expressions ARE more complicated than wildcards, but they can
> do a whole lot more. There are more than the items listed below, like
> zero-width lookahead and lookbehind assertions, but this little cheat
> sheet will work for you 99% of the time.
>
> Most regex tokens fall into one of four categories:
>
> 1. What kind of character is it?
> --------------------------------
>
> [] - Any of the characters inside the brackets will match, use the
> dash to indicate a range.
> Examples: [a-z] will match any letter.
> [aeiou] will match any vowel
> \w - "word" characters. Basically matches [a-z0-9_]
> \s - "whitespace" characters. matches spaces, tabs, etc.
> \d - any digit. Basically matches [0-9]
> \t - a tab character
> . - any character
>
>
> 2. How many characters? (the below appear after the character class)
> -----------------------
>
> {x} - Matches x number of characters
> {x, y} - Matches minimum x number of characters, maximum y characters
> Examples: \d{4} matches 4 digits
> * - Matches ZERO or more of the character (as many as possible)
> + - Matches ONE or more of the character (as many as possible)
> *? - Matches ZERO or more characters (as few as possible)
> +? - Matches ONE or more characters (as few as possible)
>
>
> 3. Where is the character?
> --------------------------
>
> \b - matches a word boundary, without actually absorbing any
> characters
> ^ - matches the beginning of a string
> $ - matches the end of a strong
>
>
> 4. Grouping
> -----------
>
> () - Any characters between the parentheses will be their own group.
> Check $matches after using -match to see the groups.
> | - A pipe character is the OR character
> Example: (one|two) will match the word "one" or the word "two"
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
$Variables into Regular expressions ?! help PowerShell
regular expressions to replace but keep character? VB Script
New lines in regular expressions PowerShell
How to work with regular expressions PowerShell
Regular expressions PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46