VUNETdotUS wrote:
On Oct 24, 11:56 am, "Evertjan." <exjxw.hannivo. ..@interxnl.net >
wrote:
>VUNETdotUS wrote on 24 okt 2007 in comp.lang.javas cript:
>>How can I get the text after matching string is found:
var str = "1111>AAAA<2222 >BBBB<3333>CCCC ";
if(str.indexO f("2222>")){
//how to get "BBBB" value following my "2222>" but before "<3333"
or any < sign?
}
Please, recommend a RegEx if possible. Thanks.
<script type='text/javascript'>
var stri = "1111>AAAA<2222 >BBBB<3333>CCCC ";
var search = "2222";
var re = new RegExp('('+sear ch+'>)([^<$]*)','');
var result = stri.match(re);
result = (result)?result[2]:'Not found';
alert(result );
</script>
[...]
Please quote only what you are referring to.
I wonder why if I make global search like var re = new
RegExp('('+sear ch+'>)([^<$]*)','g'); then result[2] cannot be used but
result can?
,-[ECMAScript Ed. 3 Final]
|
| 15.5.4.10 String.prototyp e.match (regexp)
|
| If `regexp' is not an object whose [[Class]] property is "RegExp", it is
| replaced with the result of the expression new RegExp(regexp). Let
| `string' denote the result of converting the this value to a string.
| Then do one of the following:
|
| • If regexp.global is `false': Return the result obtained by invoking
| RegExp.prototyp e.exec (see section 15.10.6.2) on `regexp' with `string'
| as parameter.
|
| • If regexp.global is `true': Set the regexp.lastInde x property to 0 and
| invoke RegExp.prototyp e.exec repeatedly until there is no match.
| If there is a match with an empty string (in other words, if the value
| of regexp.lastInde x is left unchanged), increment regexp.lastInde x by 1.
| Let n be the number of matches. The value returned is an array with
| the length property set to n and properties 0 through n–1 corresponding
| to the first elements of the results of all matching invocations of
| RegExp.prototyp e.exec.
HTH
PointedEars