Home > front end >  For a regular alternative content
For a regular alternative content

Time:10-02

Please write a JS regular will be great god: ABCD123 - test data, test data replace ABCD123

Namely out behind the string - Chinese contain -

Note: string may contain parentheses ()
Such as:
(ABCD123 - test data, test data)

(ABCD123)


CodePudding user response:

STR. Replace (/[^)] +/, "")

CodePudding user response:

reference 1/f, the sky wave response:
STR. Replace (/- +/[^)], "")


InnerHTML. Replace (/- +/[^)], "") to replace after all is blank,,

CodePudding user response:

STR. Replace (/- [\ u4e00 \ u9fa5] +/, "")

CodePudding user response:

The
reference 3 floor sky waves reply:
STR. Replace (/- [\ u4e00 \ u9fa5] +/, "")


Use the regular can be replaced, but only replaced the whole amount to achieving a replacement as long as there is related to replace?

CodePudding user response:

good reference 4 floor p-code response:
Quote: refer to the third floor of the sky wave response:

STR. Replace (/- +/[\ u4e00 - \ u9fa5], "")


Use the regular can be replaced, but only replaced the whole amount to achieving a replacement as long as there is related to replace?

STR. Replace (/- [\ u4e00 \ u9fa5] +/g, "")

CodePudding user response:

refer to fifth floor of the sky wave response:
Quote: good reference 4 floor p-code response:

Quote: refer to the third floor of the sky wave response:

STR. Replace (/- +/[\ u4e00 - \ u9fa5], "")


Use the regular can be replaced, but only replaced the whole amount to achieving a replacement as long as there is related to replace?

STR. Replace (/- [\ u4e00 \ u9fa5] +/g, "")


Hello, expression is not applicable to this: road - test HH and UI test


"Road - test HH and UI test". The replace (/- [\ u4e00 \ u9fa5] +/g, "") results into ABCD1234HH and UI test
Not - that in front of a bunch of, can deal with?

CodePudding user response:

refer to fifth floor of the sky wave response:
Quote: good reference 4 floor p-code response:

Quote: refer to the third floor of the sky wave response:

STR. Replace (/- +/[\ u4e00 - \ u9fa5], "")


Use the regular can be replaced, but only replaced the whole amount to achieving a replacement as long as there is related to replace?

STR. Replace (/- [\ u4e00 \ u9fa5] +/g, "")


AB - CD01-001-00001 - test data TEST123 this cannot directly apply to the last character in front of all the content result: AB - CD01-001-00001

CodePudding user response:

You want to replace the rules of the detailed clear, otherwise others write regular may only apply to your given example,
The replace (/- [] \ u4e00 - \ u9fa5 \ w + (? ! [\ u4e00 - \ u9fa5 \ w] | -)/g, "")

CodePudding user response:

reference sky waves on the eighth floor response:
do you want to replace the rules of the detailed clear, otherwise others write regular may only apply to your given example,
The replace (/- [] \ u4e00 - \ u9fa5 \ w + (? ! [\ u4e00 - \ u9fa5 \ w] | -)/g, "")


The replace (/- [] \ u4e00 - \ u9fa5 \ w + (? ! [\ u4e00 - \ u9fa5 \ w] | -)/g, "")

Just want to replace the string content behind the first character is - all of the content, regardless of the first character - followed by Chinese alphanumeric punctuation all content is replaced with an empty

Var STR='AB - CD01-001-00001 - test'

Output: AB can

CodePudding user response:

references 9 f good p-code response:
Quote: refer to the eighth floor of the sky wave response:

You want to replace the rules of the detailed clear, otherwise others write regular may only apply to your given example,
The replace (/- [] \ u4e00 - \ u9fa5 \ w + (? ! [\ u4e00 - \ u9fa5 \ w] | -)/g, "")


The replace (/- [] \ u4e00 - \ u9fa5 \ w + (? ! [\ u4e00 - \ u9fa5 \ w] | -)/g, "")

Just want to replace the string content behind the first character is - all of the content, regardless of the first character - followed by Chinese alphanumeric punctuation all content is replaced with an empty

Var STR='AB - CD01-001-00001 - test'

Output: AB can


Punctuation marks are included? The following including Chinese, and English _,.
"AB - CD01-001-000.01 - the test, the test data TEST123". The replace (/- [\ u4e00 - \ \ u9fa5 \ w -,,,. \] +/g, "")

CodePudding user response:

references to the tenth floor of the sky wave response:
Quote: good, 9/f, reference p-code response:

Quote: refer to the eighth floor of the sky wave response:

You want to replace the rules of the detailed clear, otherwise others write regular may only apply to your given example,
The replace (/- [] \ u4e00 - \ u9fa5 \ w + (? ! [\ u4e00 - \ u9fa5 \ w] | -)/g, "")


The replace (/- [] \ u4e00 - \ u9fa5 \ w + (? ! [\ u4e00 - \ u9fa5 \ w] | -)/g, "")

Just want to replace the string content behind the first character is - all of the content, regardless of the first character - followed by Chinese alphanumeric punctuation all content is replaced with an empty

Var STR='AB - CD01-001-00001 - test'

Output: AB can


Punctuation marks are included? The following including Chinese, and English _,.
"AB - CD01-001-000.01 - the test, the test data TEST123". The replace (/- [\ u4e00 - \ \ u9fa5 \ w -,,,. \] +/g, "")


Includes all characters content is including any character

CodePudding user response:

Must be a regular? Do not use other ways to regular line not line?
Var STR="AB - CD01-001-000.01 - measurement, ~ # % & amp; (* ^ & amp; * & amp; Data () * _, try TEST123 ";
STR. Slice (0, STR. IndexOf (' - '))
  • Related