![](/img/trans.png)
[英]How can I write a regular expression that matches everything between the first and the last quote?
[英]How do I write a regular expression that matches everything except a left and right parenthesis and anything between them
我正在使用javascript,並嘗試編寫一個正則表達式,該表達式匹配除左括號和右括號以及它們之間的任何內容以外的所有內容。 經過一些研究之后,我在Stackoverflow上提出了一個類似的示例。 在此特定示例中,以下正則表達式用於匹配除999之外的任何三位數。
[(?!999)(\d{3})][1]
此正則表達式按預期工作,並且匹配555或444或333,但不匹配999。
我希望我的正則表達式匹配如下:
John Smith => John Smith
John Smith (RET) => John Smith
Mr. John Smith's (RET) (1st) => Mr. John Smith's
John William Smith (RET) => John William Smith
John => John
這是我到目前為止的內容,但是沒有用:
(?!\([A-Za-z]?\))(.*)
有人可以告訴我我哪里出錯了。
這是您要找的東西嗎?
[^\(\)]*
我添加了一個帶有輸入的插圖,該輸入在有效匹配項下變為綠色,在無效匹配項下變為紅色
input:focus:invalid { background:red; } input:focus:valid { background:green; }
<input class="pattern" pattern = "[^\\(\\)]*" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.