For example, a for b of c When there's this sentence, I want to extract the word "for" before and after.
Let's say the function we extract is func func("a for b of c", "for", 1) -> a func("a for b of c", "for", 2) -> b I'm trying to make sure that's what I'm trying to do.
If you know the oracle version, please reply.
Thank you.
** I don't know how to change the line ㅠ<
regex
You can use the groupings.
(.*) for (.*)
Interpreted by
(Any letter or group with 0 or more in front of for) for (Any letter or group with 0 or more after for)
This is.
If you look at the Python code, you can write it as follows.
import re
search_target = 'shgdklahslktdgjwaolsdtgaswd for waseghtiouwaegtyawehtoi'
regex = '(.*) for (.*)'
r = re.search(regex, search_target)
if r:
print(r.group(1))
print(r.group(2))
If you press "Run" and run it on the code executor, you will see two lines printed out. You can use either group (1) or group (2).
© 2024 OneMinuteCode. All rights reserved.