You are viewing limited content. For full access, please sign in.

Question

Question

Ignore any space in a pattern match

asked on February 13, 2014

I am stuck on a pattern match inside a workflow. How do I tell the pattern to ignore any space and only grab numbers?

 

I need to match the second set of numbers in the pattern #123#456#. In that example, I'd like to grab 456. 

 

As it will not always be 3 numbers in between the # symbols, I would use #\d+#(\d+)#

 

However, the text i'm pulling is from an OCR'd document and the OCR is not always 100% accurate. Sometimes it throws a space randomly any where between the numbers. There is no consistency to the number of spaces or their location. ex: # 1 2 3 #4 5  6#  or  #123#45  6#  or  #1 23# 456 #

 

I want to grab 456(or any number) no matter if there are spaces anywhere in between the # symbols. Is this possible? It's driving me nuts.... I see something about using (?x) but I cannot figure out where to put that in my expression. 

 

Thanks in advance! 

0 0

Answer

SELECTED ANSWER
replied on February 17, 2014

Oops, try ([^\s]+). 

1 0

Replies

replied on February 13, 2014

Once you specify the text around the matching group, it gets complicated to say you want just parts of the data inside the matching group. So it'd be easier to just get everything in between the # signs with something like #[^#]+#([^#]+)# and then run the resulting value through a second pattern matching that strips out the spaces.

1 0
replied on February 13, 2014

I follow the logic Miruna, thank you! That's what I was thinking...

 

I'm stuck on exactly how to strip out the spaces in the second pattern match though.  

 

If I pull "4 5 6" from #123#4 5 6#, what pattern would I run on the "4 5 6" to return "456" or any amount of numbers with any number of spaces and return only numbers?

 

Thank you so much!!!

0 0
replied on February 13, 2014

So, the way I usually do this is by specify what I'm trying to exclude with "characters not in range" ([^range goes here]). So something like ([^\\s]+) set to all matches combined with not spaces. That way, pattern matching will look at "4 5 6" or and pick out things that are not spaces. "All matches" is what tell Pattern Matching to keep going past the first space it finds.
 

0 0
replied on February 14, 2014

I must be missing something.... 

 

When I put in ([^\\s]+) as the pattern and test "4 5 6" it returns "4 5 6" and not "456" (the later is what I'm hoping to get, all numbers no space). 

 

Is there any further tips or thoughts on how I could accomplish this?

 

Thanks so much for your patience, time, and help!

0 0
SELECTED ANSWER
replied on February 17, 2014

Oops, try ([^\s]+). 

1 0
replied on February 17, 2014

Thank you so much!!! I'm so glad to have this one solved smiley

 

Just in case anyone finds this post in the future, make sure to select "All Matches (combined with no spaces)" from the drop down list just above the testing area. I missed that the first time. 

0 0
replied on February 17, 2014

For the record, the extra \ was turning the backslash into a literal, so pattern matching was looking for things that were not "\" or "s". The fact that it returned the whole value ("4 5 6") is an indication that pattern matching didn't find matches (QF defaults to "use input value as the token value when no matches are found", which can also be changed from the same dialog where you configure it).

2 0
replied on July 1, 2014

How do you add space to multiple line capture?

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.