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

Question

Question

How to retrieve specific portion of a sentence using Regular Expression

asked on June 9, 2020

We are trying to retrieve all words after keyword "To" in a sentence using Regular Expression.

 

For e.g. We would like to retrieve:

1) "South Dakota" from the Sentence "Kentucky to South Dakota"

2) "Kansas City" from the Sentence "Montana to Kansas City"

3) "New York" from the Sentence "Michigan to New York"

0 0

Answer

SELECTED ANSWER
replied on June 9, 2020

A lot of the pattern will depend on how the text is gotten.  If it is OCRed, there is a lot more chance for erroneous characters and you may have to account for many possible variations

You could try starting with something like:

[Tt][Oo0]\s+(\S[^\r\n]+)

1 0
replied on June 10, 2020

This worked. Thanks Bert.

0 0

Replies

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

Sign in to reply to this post.