Reputation: 31
I lost a hope to find a solution by myself..
I need a regex to find a word(w) in a text which start with plus sign (+), but ignore words which start with 2 or more plus signs,
i.e. in string
"+aaa +bbb ++ccc ddd eee+ fff++ +ggg hhh"
it should find
"aaa, bbb, ggg"
Thanks for any help
Upvotes: 3
Views: 248
Reputation: 107287
You can use following regex:
(?:\s|^)\+(\w+)
Demo : https://regex101.com/r/nU3oH3/4
Upvotes: 2
Reputation: 1234
(^|\s+)\+(\w+)
https://regex101.com/r/bR1yF7/2
MATCH 1
1. [0-0] ``
2. [1-4] `aaa`
MATCH 2
1. [4-5] ` `
2. [6-9] `bbb`
MATCH 3
1. [30-31] ` `
2. [32-35] `ggg
Upvotes: 1
Reputation: 6856
This would find the three matches:
(^|[^\+])\+(\w+)
fiddle: https://regex101.com/r/vD6iQ4/2
Upvotes: 1