Hi all,
I'm using Pattern Matching to get what I want but it looks like I make mistake.
This is my pattern : Field:\s?(.*)\s?Numb
For me, the "\s?" means 1 or 0 espace, right?
My first space didn't pick, but why my last one was picked?
Hi all,
I'm using Pattern Matching to get what I want but it looks like I make mistake.
This is my pattern : Field:\s?(.*)\s?Numb
For me, the "\s?" means 1 or 0 espace, right?
My first space didn't pick, but why my last one was picked?
Pattern Matching will always match as much as possible. So in this case, the first space is part of the pattern before the match group, while the last one is part of the match group itself because it matches the pattern for the group and you're saying it's ok to have no spaces before "Numb".
Something like Field:\s?(.*[^\s])\s?Numb specifically says the last character in the match group is not a space ("[^\s]"), so it will leave the last space out of the returned value.
Miruna,
Last question about pattern
How can I do if the "caractere" is blank or a word?
For exemple : "Field: Ab 123 Number" or "Field: Ab 123Word Number"
Field:\s?(.*[^\s]|[^Word])\s?Numb is it alright?
By "word" you mean a specific word that's always the same or a word that could change between values?
If it's the second case, how would you describe the value before it? Is it always 3 digits? Could it be letters?
By "word" I mean a specific word (always the same).
You can also add a '?' at the end of your match group.
Field:\s?(.*?)\s?Number
Adding the '?' tells the match to be non-greedy and will match the least amount of data while allowing the rest of the regexp to match.
Without the '?' it will match as much as it possibly can.
Thanks all.
It's working.
The 2 ways are give me the same result.