Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

REGEX Expression

anjanarnair
7 - Meteor

Hi

could anyone can please explain the below regex formula's working.

 

(.+?)(?:\s{2,}|$)

 

Thanks

 

Anjana

4 REPLIES 4
MarqueeCrew
20 - Arcturus
20 - Arcturus

@anjanarnair ,

 

Courtesy of Regex101.com

 

/
(.+?)(?:\s{2,}|$)
/
gm
 
1st Capturing Group
(.+?)
 
.
matches any character (except for line terminators)
 
+? matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
 
Non-capturing group
(?:\s{2,}|$)
 
1st Alternative
\s{2,}
 
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
{2,} matches the previous token between 2 and unlimited times, as many times as possible, giving back as needed (greedy)
 
2nd Alternative
$
$ asserts position at the end of a line
 
 
 
matches the characters literally (case sensitive)
 
Global pattern flags
g modifier: global. All matches (don't return after first match)
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
 
Cheers,
 
Mark
Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
MarqueeCrew
20 - Arcturus
20 - Arcturus

@anjanarnair ,

 

 

Record1:     one lazy fox
Record2:     one  lazy  fox
Record3:     one lazy  fox

 

Record 1 Result:   "one lazy fox"  it didn't match anything because there are no double spaces

Record 2 Result:  "one", "lazy", "fox" each word is matched because there are double spaces

Record 3 Result:  "one lazy" "fox" there is only 1 space between one & lazy and there is a double space after lazy.

 

Cheers,


Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
PhilipMannering
16 - Nebula
16 - Nebula

It's saying return the string up until the last colon and two or more spaces. If the colon and two or more spaces do not exist at the end, then return everything.

anjanarnair
7 - Meteor

Thanks for the clarification!

Labels