473,326 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Java Script Regular Expressions

I am a wreck at regular expressions so I could use a little help.

Say I have a url that looks something like this.
http://test.com/test/test2/tabid/656/Default.aspx. I need to be able
to pull out only the word test2. I wont know that the word is going
to be test2 when I use the regular expressions so I need to find
everything between / and /tabid because that is the only thing that
will be the same no matter what.

Feb 13 '08 #1
3 1251
wrote on 14 feb 2008 in comp.lang.javascript:
I am a wreck at regular expressions so I could use a little help.

Say I have a url that looks something like this.
http://test.com/test/test2/tabid/656/Default.aspx. I need to be able
to pull out only the word test2. I wont know that the word is going
to be test2 when I use the regular expressions so I need to find
everything between / and /tabid because that is the only thing that
will be the same no matter what.
<script type='text/javascript'>

var t = 'http://test.com/test/test2/tabid/656/Default.aspx';

t = t.replace(/.+\/([^\/]+)\/tabid\/.+/,'$1')

alert(t);
</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 13 '08 #2
De**********@gmail.com meinte:
I am a wreck at regular expressions so I could use a little help.

Say I have a url that looks something like this.
http://test.com/test/test2/tabid/656/Default.aspx. I need to be able
to pull out only the word test2. I wont know that the word is going
to be test2 when I use the regular expressions so I need to find
everything between / and /tabid because that is the only thing that
will be the same no matter what.
Untested:
/\/(.*?)\/tabid/

Gregor
--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Feb 13 '08 #3
Gregor Kofler wrote:
De**********@gmail.com meinte:
>Say I have a url that looks something like this.
http://test.com/test/test2/tabid/656/Default.aspx. I need to be able
to pull out only the word test2. I wont know that the word is going
to be test2 when I use the regular expressions so I need to find
everything between / and /tabid because that is the only thing that
will be the same no matter what.

Untested:
/\/(.*?)\/tabid/
Less error-prone because not using the non-greedy subexpression and not
allowing the empty string:

/\/[^\/]+\/tabid/
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Feb 17 '08 #4

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

Similar topics

73
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities...
2
by: Lionel | last post by:
Hi all, I would like having more informations on how we could exchange informations and/or objects between PERL and JAVA. We have a Java programs that open, maintain and close telnet...
6
by: John Smith | last post by:
Hello, I have a rather odd question. My company is an all java/oracle shop. We do everything is Java... no matter what it is... parsing of text files, messaging, gui you name it. My question...
1
by: pawel | last post by:
I have made some comparision C# to Java RegularExpression. The problem was to find out if the rule match some text. Matching were done for precompiled regular expressions, in 100000 iterations...
11
by: rajarao | last post by:
hi I want to remove the content embedded in <script> and </script> tags submitted via text box. My java script should remove the content embedded between <script> and </script> tag. my current...
4
by: 28tommy | last post by:
Hi, I'm trying to find scripts in html source of a page retrieved from the web. I'm trying to use the following rule: match = re.compile('<script + src=+>') I'm testing it on a page that...
5
by: E2CMonkeyBoy | last post by:
Quick Intro: was thumbing through a book on Programming Windows in C# and was wondering if I shouldnt fork my developement: I've written a program in windows script, and now a more robust version...
9
by: Tuy Solang | last post by:
I download four scripts that are used to display Khmer PGN for Khmer Chess. It works fine with Netscape 7.1 on MS Millenium, but it gave me an error(Java Script console) with Netscape 8.1 on MS...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.