Answer the question
In order to leave comments, you need to log in
What regular expression to use to get part of a string?
Please help me write a regular expression to get the part of the string after the "=" sign. The expressions are:
?sort=-number
?sort=name
?sort=rating
?sort=-commits_amount
?sort=closed_issues
?sort=total_time
?sort=on_time
?
sort=percent
"or be none.
Answer the question
In order to leave comments, you need to log in
No regular expressions needed:
str.split('=').pop()
// или
str.slice(str.indexOf('=') + 1)
str.replace(/[^=]*=/, '')
// или
str.match(/(?<==).*/)[0]
// или
/[^=]*$/.exec(str).shift()
new URLSearchParams(str).get('sort')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question