I have a form with a textarea in it. I log the results to a text file on the server, but I would like to strip out any line breaks a user would put in the textarea, as well as any commas that would interfere with importing the comma-delimited log text file into Excel or something for later use.
I think this has to do with regex, but I'm no expert and could use some help. Or maybe there is an easy PHP function that will do it?
Possible Duplicate:
Count number of matches of a regex in Javascript
How can I count the number of Leading spaces in a string. In this case it would be 4:
var s = " Hello World";
// ^^^^ <-- 4 leading spaces
so the problem is, i have a contenteditable div, with a keyup function binded.
everytime somebody puts a youtube url in it, it has to be replaced by an embedded movie.
i came up with a regex like this :
content.match(/http:\/\/\w{0,3}.?youtube+\.\w{2,3}\/watch\?v=.*?(?=\s)/g);
firefox wil do the replace after a whitespace, but in ie it won't work.
any suggestions?
thnx in advance!
I want my regex to catch:
monday mon thursday thu ...
So it's possible to write something like this:
(?P<day>monday|mon|thursday|thu ...
But I guess that there should be a more elegant solution.
I have this statement:
String cap = Regex.Replace(winCaption, @"[^\w\.@-]", "");
that transforms "Hello | World!?" to "HelloWorld".
But I want to preserve space character, for example: "Hello | World!?" to "Hello World".
How can I do this?
Hi
with linux bash shell , how can i use regex to get a certain string of a file
by example:
for filename *.tgz
do
"get the certain string of filename (in my case, get 2010.04.12 of file 2010.01.12myfile.tgz)"
done
or should I turn to perl
Merci
frank
I have a variable $link_item, it's used with echo and gives the strings like
<span class="name">Google</span>http://google.com
How to remove "<span class="name">Google</span>" from string?
It should give just "http://google.com".
Heard it can be done with regex(), please help.
I want regular expression that checks
that the string doesnt start with an
empty space.
Some what like this i want to do :
Is the below ValidationExpression right for it :
string ValidationExpression = @"/^[^ ]/";
if (!String.IsNullOrEmpty(GroupName) && !Regex.IsMatch(GroupName, ValidationExpression))
{
}
hi all,
i'm having the following string
<img alt="over 40 world famous brandedWATCHES BRANDs to choose from
" src="http://www.fastblings.com/images/logo.jpg"></strong></a><br>
i want to define a regex pattern like <img alt="(.+?)" src="http://(.+?).(jpg|gif)">
but as u can see the target strings has a linebreak in the alt attribute - so how can i incorporate this? the rule should be like "anything in the alt-attribute including linebreaks"
thx
Hi.
Tumblr and other blogging websites allows people to post embeded codes of videos from youtube and all video networks.
but how they filter only the flash object code and remove any other html or scripts? and even they have an automated code that informes you this is not a valid video code.
Is this done using REGEX expressions? And Is there a PHP class to do that?
Thanks
Hi,
I've got this regex (I'm not good at it) /http://www.youtube.com/watch?v=[a-zA-Z0-9_]/i it has to match any youtube watch url (because youtube always redirects to that domain)... It should match http://www.youtube.com/watch?v=iMXCqgWjpL8 but it doesn't.
Can someone help me?
Regard,
dodo
I am trying to write a regular expression for somethin like
s1 = I am at Boston at Dowtown
s2 = I am at Miami
I am interested in the words after at eg: Boston, Downtown, Miami
I have not been successful in creating a regex for that. Somethin like
> .*? (at \w+)+.*
gives just Boston in s1 (Downtown is missed). it just matches the first "at" Any suggestions
I'm having some troubles getting regex to replace all occurances of a string within a string.
**What to replace:**
href="/newsroom
**Replace with this:**
href="http://intranet/newsroom
This isn't working:
str.replace(/href="/newsroom/g, 'href="http://intranet/newsroom"');
Any ideas?
Thanks,
Tegan
What would the regex expression that would go into preg_split function to validate date in the format of
7-Mar-10 or how can I validate a date of format 7-Mar-10 in PHP
Thanks.
I have a string like so:
option_alpha="value" option_beta="some other value" option_gamma="X" ...etc.
I'm using this to parse them into name & value pairs:
preg_match_all("/([a-z0-9_]+)\s*=\s*[\"\'](.+?)[\"\']/is", $var_string, $matches)
Which works fine, unless it encounters an empty attribute value:
option_alpha="value" option_beta="" option_gamma="X"
What have I done wrong in my regex?
Trying to use regex refind tag to find the content within the brackets in this example using coldfusion
joe smith <[email protected]>
The resulting text should be
[email protected]
Not having any luck. Any suggestions?
I have the following regex expression which is to extract the source of any img tag in HTML.
/(<img).*(src\s*=\s*"([a-zA-Z0-9\.;:\/\?&=\-_|\r|\n]{1,})")/isxmU
However, it doesn't appear to be matching the following:
<IMG SRC='http://www.mysite.com/pix/lens/mtf/CAEF8512L.gif'>
How can I build it to match this as well?
My string contain a lot of HTML entities, like this
"Hello <everybody> there"
And I want to split it by HTML entities into this :
Hello
everybody
there
Can anybody suggest me a way to do this please? May be using Regex?
Hi Guys,
I have a bit of php code like this:
$test = "<!--my comment goes here--> Hello World";
Now i want to strip the whole html comment from the string, i know i need to use preg_replace, but now sure on the regex to go in there.
Can anybody help?
Thanks
I know that the following regex will match "red", "green", or "blue".
red|green|blue
Is there a straightforward way of making it match everything except several specified strings?
Alright so I want to grab the information on a website thats between
[usernames] and [/usernames]
I know how to get the string but how would I use regex to only have the information in the middle.
Remember I am going to be having more then one thing on the page.
In Java regular expression, it has "\B" as a non-word boundary.
http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html
If I have a 'char', how can I check it is a non-word boundary?
Thank you.
I need a model for finding all of the regular expressions that would match a particular string. Basically, I need an algorithm for doing what I do to generate a regex search string from some pattern.
My purpose for this to create a list of potential regular expressions from a selection of text and order that list from least specific (i.e. string of characters with abitrary length) to most specific (i.e. the string itself) to be used in text editor.
I want a regex to find the following types of strings:
http://anything.abc.tld
http://anything.abc.tld/
where
abc - abc always remains abc
anything - it could be any string
tld - it could be any tld (top-level-domain) like .com .net .co.in .co.uk etc.
Note: The url must not contain any other thing at the end, means http://anything.abc.tld/xyz is not acceptable.