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

Question

Question

Regular Expression to extract string between two strings

asked on September 13, 2023

Hi everyone,

Can anyone give me some tips on how I can pull text between two texts? The expression I currently have only takes whatever comes after the first text [\s|\n|\r|\v|\f|\t]*([^\n]+)

 

In my example below, I would like to pull the text between Reference #: and Urgency:, which is supposed to be blank.

 

 

Any tips would be greatly appreciated, thank you!

0 0

Answer

SELECTED ANSWER
replied on September 20, 2023

That's because parentheses are reserved characters for regular expressions and you need to escape them if you want them treated as "normal" parentheses.

Try using "Task\(s\)" instead of "Task(s)" in your pattern.

1 0

Replies

replied on September 13, 2023 Show version history

Your regular expression says newline characters (i.e., \r and \n) are allowed right after "Reference #:", so the regular expression then looks for everything that's not a newline character after the newline at the end of the "Reference #:" line.

The "|" is unnecessary in " [\s|\n|\r|\v|\f|\t] " because square brackets indicate a range.

I think if you use Reference #: [\s\v\f\t]*([^\r\n]+) it should do what you need.  

2 0
replied on September 13, 2023

Thank you very much Miruna! This is exactly what I needed.

0 0
replied on September 20, 2023

Hi Miruna,

I encountered an issue where it doesn't pull the value if the string has "(s):", any tips?

 

0 0
SELECTED ANSWER
replied on September 20, 2023

That's because parentheses are reserved characters for regular expressions and you need to escape them if you want them treated as "normal" parentheses.

Try using "Task\(s\)" instead of "Task(s)" in your pattern.

1 0
replied on September 20, 2023

Thank you so much Miruna! This solved it.

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

Sign in to reply to this post.