| |

VerySource

 Forgot password?
 Register
Search
View: 1081|Reply: 6

Ask how to write regular expressions

[Copy link]

3

Threads

11

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-12-9 10:30:01
| Show all posts |Read mode
How to write a regular expression with any character in the middle, starting with abc and ending with 456?
Reply

Use magic Report

3

Threads

11

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-12-9 12:15:01
| Show all posts
Start with: ^abc
End with: 456$

Is any character in the middle represented by *? How to write it in combination?
Reply

Use magic Report

3

Threads

11

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-12-9 12:30:01
| Show all posts
There are some discrepancies in the beginning, it should be like this:

How to write a regular expression that starts with abc and ends with 456, with an arbitrary string of indefinite length in the middle?
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-12-9 12:45:01
| Show all posts
example:
$text='abcXXTGFTdfd3245
fzxcv456';

if(preg_match('/^abc.*456$/is',$text)){
  echo'match';
}else{
  echo'does not match';
}
Reply

Use magic Report

3

Threads

11

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-12-9 13:00:01
| Show all posts
What does the /is inside mean?
Reply

Use magic Report

3

Threads

11

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-12-9 13:15:01
| Show all posts
I wrote one myself, following the way upstairs.

$pagecode=@file_get_contents("http://www.baidu.com");

if(preg_match('/^<a onclick.*>$/is',$pagecode)){
  echo'match';
}else{
  echo'does not match';
}

I don't know why it doesn't match.
Reply

Use magic Report

3

Threads

11

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-12-9 13:30:01
| Show all posts
That's it, thanks

Suddenly
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