none
Regex Pattern Matching and wildcard retrieval RRS feed

  • Question

  • Hi all,

    So I have a long string that contains placeholder strings throughout it, like so:

    string input = "abcdefg[MARK]h[MARK]ijklmn[MARK]p[MARK]qrstuvwxyz";

    I wish to parse this string for occurences of "[MARK]" + singlewildcardchar + "[MARK]";

    In the above example I'd like to return the letters 'h' and 'p'. How can I do this with Regex Patterns? Or is there a simpler way?

    Thanks,

    Jib

    Friday, January 5, 2018 3:03 PM

Answers

  • As long as it is always a single character between the [MARK] placeholders (and more than a single character elsewhere) then you can use the pattern:

    \[MARK\](.)\[MARK\]

    There are several places you can test out patterns online, which is very handy. E.g. http://regexstorm.net/tester

    • Marked as answer by Jibrohni Friday, January 5, 2018 3:52 PM
    Friday, January 5, 2018 3:17 PM

All replies

  • As long as it is always a single character between the [MARK] placeholders (and more than a single character elsewhere) then you can use the pattern:

    \[MARK\](.)\[MARK\]

    There are several places you can test out patterns online, which is very handy. E.g. http://regexstorm.net/tester

    • Marked as answer by Jibrohni Friday, January 5, 2018 3:52 PM
    Friday, January 5, 2018 3:17 PM
  • Many thanks, that's a handy little resource too.

    Jib

    Friday, January 5, 2018 3:53 PM