Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

Notepad++/Python Regex

ocopmat

Recruit
Basic Member
Messages
12
Reaction score
0
Points
16
Hi,

May marunong po ba sainyo gumamit ng regex (notepad++ or kahit idea lng ng pattern) ?

Bale may string kasi ako na
"
START foo bar baz
START foo baz
START bar bar
START foo
START baz qux
START bar qux
START qux
"

Dapat makuha ko yung line na walang "foo" or "baz". Bale ang dapat na expected output ko dyan ay
"bar bar"
"bar qux"
"qux"

Sa ngayon, isang lang sa dalawang mentioned na criteria ang kaya kong gawin.
Example,
Lahat ng lines na merong "foo" or lahat ng lines na merong "baz" but not both.

Heto yung current regex pattern ko "^START(?!.*foo).*$".

Pano ko kaya mamemerge yung dalawang string? Sana may makatulong. Thanks!
 

Attachments

  • damn.png
    damn.png
    32.7 KB · Views: 25
Code:
res = re.finditer(r"^START(?!\sbaz|\sfoo)+", txt, re.MULTILINE)
for r in res:
    txt[r.start():txt.find("\n", r.start())]
[code]
 
Ayun! Salamat pre :)

Napagana ko na siya, bale dinagdagan ko lng din ng "|" operator based dun sa suggestion mo

^START(?!.*(foo|baz)).*$
 

Attachments

  • damn.png
    damn.png
    19.3 KB · Views: 11
Back
Top Bottom