Regex to match one or more characters

10,151

Solution 1

What you're looking for is the + regex operator

Solution 2

You want the .

For example: he.lo will match your hello, but not helo.

same goes for the rest.

You can easily test it here: http://regexpal.com/.

Do note that .yp. will not match typical nor gypsy, but `.yp.+' will (because of the rest of the characters)

Share:
10,151

Related videos on Youtube

Robin Rodricks
Author by

Robin Rodricks

Updated on June 04, 2022

Comments

  • Robin Rodricks
    Robin Rodricks almost 2 years

    I need to filter a set of strings with a wildcard-type search, like the following:

    • Looking for He*lo should match "Hello", but not "Helo"
    • Looking for *ant should match "pant" and "want" but not "ant"
    • Looking for *yp* should match "gypsy" and "typical"

    The * represents one or more characters. I don't mind a handwritten or regex-based search. Any ideas? The typical .NET approach for wildcards matches 0 or more, but I need 1 or more characters. How can I do this?

    • MarcinJuraszek
      MarcinJuraszek over 10 years
      + means 1 or more in regex. You can use that.
  • King King
    King King over 10 years
    + is not an operator, it's a quantifier
  • arpl
    arpl over 10 years
    and quantifiers are not operators?
  • arpl
    arpl over 10 years
    quantifier is a better word I guess thanks. From what I've googled though it's used interchangeably in regex literature.