![](/img/trans.png)
[英]Regex to capture characters between the last white space character and the end of string
[英]Regex: Get string in between characters or character and end of line
我有這些可能的字符串:
&modelIds=340&makeIds=4307,6548&stuffId=340
OR
&modelIds=340&makeIds=4307,6548
我正在嘗試提取makeIds的數組或更簡單的makeIds字符串(在本例中為“4307,6548”),稍后我將用逗號分割它們。
我已經讓它在第一種情況下工作但不是第二種使用:
var stringTest = "&modelIds=340&makeIds=4307,6548&stuffId=340"
var matches = stringTest.match(/makeIds=(.*)&\b/)
這將返回: ["makeIds=4307,2342&", "4307,2342"]
所以我可以這樣做:
var ids = matches[1];
不幸的是,這不適用於第二個字符串。 我試過/ /makeIds=(.*)?(&|$)\\b/
(.*)?(& /makeIds=(.*)?(&|$)\\b/
但這也不起作用。
你必須在巢中?
量詞。 這是一個可選的匹配。 你的意思是讓你的.*
懶惰:
/static_keywords=(.*?)(&|$)\b/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.