1
<script language='javascript' src='http://api.psusedo.com/board@top_<?=$id?>'></script>

I try to save the value of script src through regular expression in two.

One tries to save before the _ sign(Ex:http://api.psusedo.com/board@top_ ) and the other one after the _ sign.(Ex: )

\_(.*)

The string after _ including this regular expression was found.

How do I save a character string around _ and how do I do it?

1
  • 1
    What happened to the previous question you asked on this topic? Please don't duplicate questions on the same topic. Commented Mar 13, 2017 at 3:32

1 Answer 1

0

You can try this:

src\s*=\s*'([^_]*)_([^']*)'\s*>
  1. in group 1 you get the value before underscore (_) sign
  2. in group 2 you get the value after underscore (_) sign

Demo

Sample Code:

$re = '/src\s*=\s*\'([^_]*)_([^\']*)\'\s*>/';
$str = '<script language=\'javascript\' src=\'http://api.psusedo.com/board@top_<?=$id?>\'></script>';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result

var_dump($matches);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.