M
M
mivalb3212021-08-18 18:34:35
JavaScript
mivalb321, 2021-08-18 18:34:35

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

1 answer(s)
0
0xD34F, 2021-08-18
@mivalb321

No regular expressions needed:

str.split('=').pop()
// или
str.slice(str.indexOf('=') + 1)

But, of course, regular expressions are also possible:
str.replace(/[^=]*=/, '')
// или
str.match(/(?<==).*/)[0]
// или
/[^=]*$/.exec(str).shift()

In general, given what this string is and what you want to get from it:
new URLSearchParams(str).get('sort')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question