Reputation: 13
In the example below, a dialogue between two people I want to match only the interrogators text. (The text on the left)
Hello, how are you? I am fine.
What is your name? My name is Simon.
What does Simon say? Put your hands on your head.
When I perform a regular expression individually on each line I want to extract
Hello, how are you?
What is your name?
What does Simon say?
However, I also want to allow for room for error in the questioning text allowing for up to 5 white spaces between words. The number of white space between the questioner and the answerer is always over 5 characters.
I have tried this
([^ ]| {0,5})*
but that captures the whole line
And this
[^( {0,5})]+
but I guess you can't use parenthesis in between brackets to evaluate the inner text first and specify that as a single character.
Any ideas are welcome, thanks :)
Upvotes: 1
Views: 3901
Reputation: 20683
Why don't just use split instead of match?
str.split("\s{6,}")
Upvotes: 0
Reputation: 838954
Try capturing using this regular expression:
^(.*?) {5}
The *?
is a non-greedy match, meaning that it will find the shortest match rather than the longest. This should give you what you need.
See it working online: rubular
Upvotes: 3