hi! i often wish there was an off-topic section here as the wealth of knowledge outside of XY from our community is tremendous. i have exhausted my searching and testing and have quite frankly given up.
i have spent the better half of the last 2 days trying to create/solve a regex pattern. i can get the individual "parts" working relatively easy; however, not combined. i also refuse to "ask" some AI site for help and honestly, the toxicity of other services and forums is too much.
i am trying to match a set of keywords only inside of double-quotes. i can match the keywords and i can match the quoted text, but just combined.
example keywords:
TEST SAMPLE DEPOSIT
example string:
this is a TEST for matching "keywords like TEST and SAMPLE inside of quotes" but not this TEST and DEPOSIT because they are outside
attempting to match:
this is a TEST for matching "keywords like TEST and SAMPLE inside" of quotes but not TEST and DEPOSIT because they are outside
would it be possible to create an technical-only off-topic section only available to logged-in members ?
Trouble with Regex
-
- Posts: 224
- Joined: 29 Sep 2022 14:20
- Location: Win10 @125%
Re: Trouble with Regex
Code: Select all
$example = <<<>>>
this is a TEST for matching "keywords like TEST and SAMPLE inside of quotes" but not this TEST and DEPOSIT because they are outside
>>>;
$keywords = "TEST|SAMPLE|DEPOSIT";
$match = regexmatches($example, "[""][^""]*?" . "($keywords)" . "[^""]*?[""]", <crlf>);
text $match; // "keywords like TEST and SAMPLE inside of quotes"
One of my scripts helped you out? Please donate via Paypal
-
- Posts: 224
- Joined: 29 Sep 2022 14:20
- Location: Win10 @125%
Re: Trouble with Regex
thank you! i don't think my attempt at formatting worked in my post. i tried to bold only what i was trying to get.
i did get your exact result; however, i am trying to only get the keywords inside the quotes and not the fully quoted text.
so instead of this :
i am trying for this :
(only the found ones inside quotes, ignore other quoted text and outside-the-quotes matched keywords).
this is a tricky one !
i did get your exact result; however, i am trying to only get the keywords inside the quotes and not the fully quoted text.
so instead of this :
Code: Select all
text $match; // "keywords like TEST and SAMPLE inside of quotes"
Code: Select all
text $match; // TEST SAMPLE
this is a tricky one !
Re: Trouble with Regex
And why is it a problem if you use a following
regexmatches()
to get the keywords out of the previous match?One of my scripts helped you out? Please donate via Paypal
-
- Posts: 224
- Joined: 29 Sep 2022 14:20
- Location: Win10 @125%
Re: Trouble with Regex
I don't think that this is solvable in a single pass (in that case via regexreplace()) because it would stop after finding the first occurrence of any of the three test keywords
One of my scripts helped you out? Please donate via Paypal