Asked  7 Months ago    Answers:  5   Viewed   36 times

I have a string. The end is different, such as index.php?test=1&list=UL or index.php?list=UL&more=1. The one thing I'm looking for is &list=.

How can I match it, whether it's in the middle of the string or it's at the end? So far I've got [&|?]list=.*?([&|$]), but the ([&|$]) part doesn't actually work; I'm trying to use that to match either & or the end of the string, but the end of the string part doesn't work, so this pattern matches the second example but not the first.





Note that when you use a bracket expression, every character within it (with some exceptions) is going to be interpreted literally. In other words, [&|$] matches the characters &, |, and $.

Tuesday, June 1, 2021
answered 7 Months ago

If I understand you correctly, something like this might work:


Match hyphen (-) followed by one or more digits (d+) just before the end of the string ($). Capture the digits only ( (...) ).

Saturday, May 29, 2021
answered 7 Months ago

It is clear your text contains a linebreak other than LF. In .NET regex, a dot matches any char but LF (a newline char, n).

See Multiline Mode MSDN regex reference

By default, $ matches only the end of the input string. If you specify the RegexOptions.Multiline option, it matches either the newline character (n) or the end of the input string. It does not, however, match the carriage return/line feed character combination. To successfully match them, use the subexpression r?$ instead of just $.

So, use


The .+?r?$ will match lazily any one or more chars other than LF up to the first CR (that is optional) right before a newline.

Or just use a negated character class:


The [^rn]+ will match one or more chars other than CR/LF.

Tuesday, June 15, 2021
answered 6 Months ago

According to article 11.5.2. Regular Expressions in MySQL's documentation, you can perform selections with a regular expression with the following syntax

SELECT field FROM table WHERE field REGEX pattern

In order to match simple URLS, you may use

SELECT field FROM table
 WHERE field REGEXP "^(https?://|www\.)[.A-Za-z0-9-]+\.[a-zA-Z]{2,4}"

This will match most urls like


But not

  • htp://
  • http://google.c
  • httpf://
Saturday, August 7, 2021
answered 4 Months ago

The problem is that b, the word boundary anchor, only matches between alphanumeric and non-alphanumeric characters, so it won't match after a # (unless that is itself followed by an alphanumeric).



No need to escape the #, either.

EDIT: Changed the regex to better reproduce the intended functionality (as I think it should be)

Currently, you're not matching some chords, though; how about


That way, you can match all of these:


I guess there is still room for improvement, though.

Saturday, November 13, 2021
answered 4 Weeks ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :