473,804 Members | 3,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple RegEx Help

How can I get the text after matching string is found:

var str = "1111>AAAA<2222 >BBBB<3333>CCCC ";

if(str.indexOf( "2222>")){

//how to get "BBBB" value following my "2222>" but before "<3333"
or any < sign?

}

Please, recommend a RegEx if possible. Thanks.

Oct 24 '07 #1
7 1730
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.indexOf( "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>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 24 '07 #2
On 24 Oct, 16:09, VUNETdotUS <vunet...@gmail .comwrote:
How can I get the text after matching string is found:

var str = "1111>AAAA<2222 >BBBB<3333>CCCC ";

if(str.indexOf( "2222>")){

//how to get "BBBB" value following my "2222>" but before "<3333"
or any < sign?

}

Please, recommend a RegEx if possible. Thanks.
pattern = /2222>(.*)</;
alert(pattern.e xec(str)[1]);

Oct 24 '07 #3
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.indexOf( "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>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
thank you very much!

Oct 24 '07 #4
On Oct 24, 11:59 am, Captain Paralytic <paul_laut...@y ahoo.comwrote:
On 24 Oct, 16:09, VUNETdotUS <vunet...@gmail .comwrote:
How can I get the text after matching string is found:
var str = "1111>AAAA<2222 >BBBB<3333>CCCC ";
if(str.indexOf( "2222>")){
//how to get "BBBB" value following my "2222>" but before "<3333"
or any < sign?
}
Please, recommend a RegEx if possible. Thanks.

pattern = /2222>(.*)</;
alert(pattern.e xec(str)[1]);
thank you very much!

Oct 24 '07 #5
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.indexOf( "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>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
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?

Oct 24 '07 #6
VUNETdotUS wrote on 24 okt 2007 in comp.lang.javas cript:
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?
Read the specs of match() on the global flag.

Programming is not a trial and error art,
but is understanding the functionality.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 24 '07 #7
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
Oct 24 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8110
by: live your lives | last post by:
i am trying to validate a simple username textbox using RegularExpressionValidator: TextBox tbUserName = new TextBox(); tbUserName.ID = "tbUserName"; string strPatternUserName = @"\W"; // i've tried using "\\W", "\w", "\\w","@\w", "/\\w", etc... // but it always prints my error msg UNLESS the textbox is set to "". // why does this not work?
7
1917
by: Razzie | last post by:
Hey all, Decided to give a shot at Regular expressions - need a bit of help :) I can't seem to find the right regex for matching words like "*test*" or *somevalue*" - in short, all words starting and ending with a *. I tried things like string regex = @"(^*\|*^)"); but it still doesn't work completely (matches on "*test" too for example). If anything could help me with this, that would be appreciated.
2
1165
by: Brian Henry | last post by:
Hi everyone, I never have worked much with regex (trying to learn it now myself) but I have a simple problem that I need to solve.. Say I have numbers like this 00023432-234 0000000034112-23 00001200034-34
5
7193
by: FBergemann | last post by:
I use SunOS 5.8, gcc 3.3.2, boost 1.33.1. I have build the entire boost package and try to compile a simple example: #include <iostream> #include <string> #include <boost/regex.hpp // Boost.Regex lib using namespace std;
4
1504
by: bg_ie | last post by:
I have the following Regex - oldString = @"C:\ta"; Regex regexEndsInBackslash = new Regex(oldString + @"\\", RegexOptions.Singleline | RegexOptions.IgnoreCase); Any ideas why none of the following are true - if (regexEndsInBackslash.Match(@"C:\ta\").Success == true) ....
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10578
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9152
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.