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

Question

Question

Pattern Matching - Whitespace

asked on August 10

I'm new to working with regex and am learning on the go with pattern matching. I've stumped myself trying to match a few lines off documents while leaving the white space proceeding newlines behind;

I've built (?s)(?<=Development involving:).*?(\S.+)(?=\(As) to capture the sample below but it also matches the white space on new lines such as before "covered" and "relaxations".

Development involving:  Construct Magic house with 34 car attached garage, covered deck,
           covered walkway, covered porch, and driveway with front and rear setback
           relaxations —Total site coverage 48.3%
      (As

If anyone has some tips to get me rolling again it would be much appreciated.

 

 

0 0

Answer

SELECTED ANSWER
replied on August 14

Something like this should do it:

Pattern Matching does not do substitutions, so you need a second activity for that.

Your patterns gets the text out as:

"Construct Magic house with 34 car attached garage, covered deck,
            covered walkway, covered porch, and driveway with front and rear setback
            relaxations —Total site coverage 48.3%"

The second pattern finds the leading spaces and uses that value in the Token Calculator activity to replace it with a single space. The final result is "Construct Magic house with 34 car attached garage, covered deck, covered walkway, covered porch, and driveway with front and rear setback relaxations —Total site coverage 48.3%".

If you have a variable number of leading spaces from line to line, this might not come out as cleanly.

 

1 0
replied on August 14

Thanks Miruna. I hadn't considered breaking it into multiple steps to get the result. Your solution worked great!

0 0

Replies

replied on August 10

What is the desired return value?

0 0
replied on August 11 Show version history

The Ideal return in case of the example would be;

Construct Magic house with 34 car attached garage, covered deck, covered walkway, covered porch, and driveway with front and rear setback relaxations —Total site coverage 48.3% 

so all text between "Development involving:" and "(As" single spaced.

*Edited for clarification

0 0
replied on August 11

Is (As single spaced. actual text that will be typed in?  Or are you referring to just a blank line?

 

0 0
replied on August 11

Sorry, a little unclear with that last line "(As" is part of the actual text, the matched result would just be all single spaced.

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

Sign in to reply to this post.