NoleloN
NoleloN

Reputation: 65

match string after period regex

I have been trying to make a regex to match the text after settings. in the following string

GPIO.setup(settings.pic_taken_led , GPIO.OUT, initial=GPIO.LOW) IE (pic_taken_led)

I have so far come up with /(?<=settings)([.]\w+)/g but it matches with the period and I need it without the period. (.pic_taken_led).

I feel I am close but I can't remove the period from the capture expression.

Upvotes: 1

Views: 491

Answers (2)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626870

You can use

(?<=settings\.)\w+
^^^^^^^^^^^^^^^

See the regex demo.

Details

  • (?<=settings\.) - a positive lookbehind that matches a location immediately preceded with settings. string
  • \w+ - one or more letters, digits, _s.

VSCode demo:

enter image description here

Upvotes: 2

mukesh210
mukesh210

Reputation: 2892

You are really close. Since you want to capture pic_taken_led, just capture the String after . So your regex should be (?<=settings).(\w+)

Upvotes: 0

Related Questions