How to write regex to handle multiple spaces?
I need a regex that will get the name of a label. The labels look like this:
lbl LabelName
The regex will need to return LabelName. I manged to make this:
(?<=\slbl\s).+?(?=\s)
This works fine as long there is only one character between "lbl" and "LabelName". If I add two spaces or more spaces then it will return the extra spaces.
I tried (?<开发者_如何学C;=\slbl\s+).+?(?=\s)
but it doesn't work either.
Does the following regular expression work for you?
lbl\s+([^\s]+)
Use this: ^lbl\s+(\S+)$
. In 1st group you obtain LabelName
.
You can keep the extra spaces with the 'lbl' part and still capture LabelName
with something like this:
^lbl\s+(.*)
精彩评论