473,396 Members | 1,996 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,396 software developers and data experts.

Regex Help to Strip Some Text

Please, help me with regular expression to grab image source in any
text string using the code below. I only need the regex to be plugged
in:

var strText = "some text <img src='image.jpg'and some text";

var separateBy = ", ";
var result = ""; // if no match, use this
var allMatches = strText.match(........--->reg exp<---........);
if (allMatches) {
result = "";
for (var i = 0; i < allMatches.length; i++) {
if (i != 0) result += separateBy;
result += allMatches[i];
}
}
alert(result)

Result should be: image.jpg
Thanks

Jul 5 '07 #1
4 1358
On Jul 5, 11:09 am, vunet...@gmail.com wrote:
Please, help me with regular expression to grab image source in any
text string using the code below. I only need the regex to be plugged
in:

var strText = "some text <img src='image.jpg'and some text";

var separateBy = ", ";
var result = ""; // if no match, use this
var allMatches = strText.match(........--->reg exp<---........);
if (allMatches) {
result = "";
for (var i = 0; i < allMatches.length; i++) {
if (i != 0) result += separateBy;
result += allMatches[i];
}
}
alert(result)

Result should be: image.jpg

What did you try for a RegExp?

(Does anyone here like constructing RegExps?)

Peter
Jul 5 '07 #2
On Jul 5, 3:32 pm, Peter Michaux <petermich...@gmail.comwrote:
On Jul 5, 11:09 am, vunet...@gmail.com wrote:
Please, help me with regular expression to grab image source in any
text string using the code below. I only need the regex to be plugged
in:
var strText = "some text <img src='image.jpg'and some text";
var separateBy = ", ";
var result = ""; // if no match, use this
var allMatches = strText.match(........--->reg exp<---........);
if (allMatches) {
result = "";
for (var i = 0; i < allMatches.length; i++) {
if (i != 0) result += separateBy;
result += allMatches[i];
}
}
alert(result)
Result should be: image.jpg

What did you try for a RegExp?

(Does anyone here like constructing RegExps?)

Peter
what would you recommend: changing group or using another method?

Jul 5 '07 #3
wrote on 05 jul 2007 in comp.lang.javascript:
Please, help me with regular expression to grab image source in any
text string using the code below. I only need the regex to be plugged
in:

var strText = "some text <img src='image.jpg'and some text";
[...]
>
Result should be: image.jpg
var strText = "some text <img src='image.jpg'and some text";
Result = strText.replace(/.*/,'image.jpg');

This works as requested

Perhaps this will appeal to you:

var strText = "some text <img src='image.jpg'and some text";
strText =
strText.replace(/(some text <img src=')|('and some text)/g,'');

Or even:

var strText = "some text <img src='image.jpg'and some text";
strText =
strText.replace(/(.*?<img src=')|('>.*)/g,'');

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 5 '07 #4
Peter Michaux <pe**********@gmail.comwrote in
news:11*********************@m37g2000prh.googlegro ups.com:

>Result should be: image.jpg


What did you try for a RegExp?

(Does anyone here like constructing RegExps?)
I gotta say, after reading "Mastering Regular Expressions" (okay, just part
of it) and using RegEx Buddy (yes, I paid for it), I kind of like making
them now. The software (RegEx Buddy) is fan-freaking-tastic.

Still doesn't mean I will do the OP's homework if he doesn't even attempt
to try!

Jul 5 '07 #5

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

Similar topics

5
by: Markus Ernst | last post by:
Hello I have a regex problem, spent about 7 hours on this now, but I don't find the answer in the manual and googling, though I think this must have been discussed before. I try to simply...
6
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
6
by: BigAl | last post by:
Perhaps someone here can help me out... RegEx: "^.*\d{5}(-\d{4})?.*$" Intended Purpose: To strip out the City/State/ZipCode line from a signature. Sample Text: Joe Jackson 131 W. 5th...
1
by: darrel | last post by:
I have some vb.net code that is running a regex, matching groups, and replacing them. I'm trying to come up with a simple script that will strip all attributes from all HTML tags. This is what I...
1
by: c | last post by:
Hello, I have a question about a Regex I'm trying to write. I'm trying to strip out the DOCTYPE declaration from a XML document I'm receiving. I've noticed that the files are delivered with...
4
by: MooMaster | last post by:
I'm trying to develop a little script that does some string manipulation. I have some few hundred strings that currently look like this: cond(a,b,c) and I want them to look like this: ...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
1
by: progman417 | last post by:
Hello, I'm using the following Rexex function to strip HTML tags from text: return Regex.Replace(text, "<.*?>", String.Empty); If I set text manually to something like "<b>test</b>" then it...
3
by: William Gill | last post by:
I am not to sharp on my regular expressions because I haven't used them in quite a while. So I am relearning regex and the PHP regex functions at the same time. Which means when I screw up, I'm...
13
Curtis Rutland
by: Curtis Rutland | last post by:
I know almost nothing of Regular Expressions other than that they exist. However, I know that it's probably the answer to my co-worker's problem. We need to strip some HTML out of some data. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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,...

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.