Remove text (& brackets) from a string with regex

前端 未结 2 487
北荒
北荒 2021-01-28 03:47

It\'s easy when you understand...unfortunately, I don\'t! I will deeply appreciate you if you can guide me to the answer, thanks.

I want to capture a string, using just

相关标签:
2条回答
  • 2021-01-28 04:11

    Your Regexp would look something like that. The acutal Syntax depends on your programming language / tool.

    First you need to match the <td ..> part. Then you capute everything upto (. then to be sure match everything in brackets followed by </td>.

    /<td[^>].*>\([^(]*\)(.*)</td>/
    

    You should read the Book: Mastering Regular Expressions by Jeffrey Friedl.

    0 讨论(0)
  • 2021-01-28 04:16

    Okay, so remove the HTML first, then do something like this to remove the (...) part:

    \s+\(.*?\)
    

    If you know the (...) part is the very last thing in the string (i.e. there's nothing after it), you can use this to check that it's at the end, too:

    \s+\(.*?\)$
    

    Just use a Regex find and replace function, find the expression above, and replace with nothing.

    0 讨论(0)
提交回复
热议问题