| |

VerySource

 Forgot password?
 Register
Search
View: 753|Reply: 2

How do I convert a string into a regular expression

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-3 19:00:02
| Show all posts |Read mode
For example: I return a string from the background: '(?: <Script. *?>) ((\n |\r |.) *?) (?: <\/ script>)'
   But in Javascript, the way we use Javascript is:
   var reg = /(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/, then use the reg test method. . But I don't know how to use strings. .
   So please ask, heroes
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-5-18 11:45:01
| Show all posts
var reg = new RegExp (string, type); // Pay attention to escaping. . type is optional case-insensitive img
// For example: matching numbers
var num = new RegExp ("\\d");
// match letters a to z (not case sensitive and match multiple)
var r = new RegExp ("[a-z]", "ig");
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-6-16 16:30:01
| Show all posts
Someone helped me solve it so quickly, thank you very much. .
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list