Wednesday, September 12, 2012 8:52 PM
In my search, most of the responses around this expression were tailored around .... that is not the purpose of Regex..... However, lets ignore the standard programming 101 comments and ponder
both yield my desired behavior. any other than white space.
so things like
abc kllk match
and empty strings fail
However, when I did /A/S+/Z it no longer matches as I anticipate
What am I missing?
Wednesday, September 12, 2012 9:22 PM
Of course /S is meaningless. I think you meant \S which mean 'Anything other than White space.
Also, \A is meaningless, I think you mean \A which means 'Beginning of string'.
Wednesday, September 12, 2012 9:23 PM
true... i apologize for the syntax error, but the intention i think was clear.
- Edited by Tyboriel Wednesday, September 12, 2012 9:25 PM
Thursday, September 13, 2012 12:36 AM
Aside from having your slashes reversed, which I assume is a typo, if your desired behavior is to match "any" other than white space, your three regexes are quite different.
Given a string "abc kllk"
\S+ will produce two matches: "abc" and "kllk"
\A\S+ will only match "abc"
\A\S+\Z will not match anything.
Consider that \A and \Z determine where the match starts.
Here is a hint: \S+\Z will match only kllk
Thursday, September 13, 2012 2:06 PM
I will accept your answer, as I did not fully define describe problem
I do not have control over the insertion of \A and \Z, as that is done by something else.
I can say that I have something that does solve my full problem.
This yields the desired result that i was searching for.
Thursday, September 13, 2012 3:13 PM
I'm glad you found something that works for you. Of course, by not defining your problem, it is difficult to obtain an appropriate answer :-)
Your regex, in fact, does match the white space between abc and klik.
It captures, into capturing group 1 "abc kllk"; and into capturing group 2: "l" (the second "l").
Thursday, September 13, 2012 3:30 PM
By the way, to elaborate a bit further on your regex, it will capture everything in the string, so long as the string does not start or end with a whitespace character. So an equivalent expression should be:
Thursday, September 13, 2012 7:31 PM
Back to the full problem, I needed to account for the start and the end spaces. The root cause of my lack of understanding was, I did not realize that the \A and \Z was basically like two pointers that said it needs to start here and end there or the answer is false. I thinking of it as two separate operations. Start from the beginning, and than start from the end. Thank you for you patients and help. I am sure this get easier with practice like most things.