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

splitting merged words but www adresses (regexp)

Is there any way to split all merged words but www and e-mail addresses?

I have regexp

preg_replace("/(\.)([[:alpha:]])/", "\\1 \\2", "www.google.com
any,merged.words my****@domain.com")

it give me incorrect result:
www. google. com any, merged. words mymail@domain. com

i need result
www.google.com any, merged. words my****@domain.com

in my case, all web addresses has www. or http:// in beggining of string
and email of course @ inside string

is it possible to write regexp like this?
Jul 17 '05 #1
2 2414

"Piotr" <pi**@gaztea.pl> wrote in message
news:1e*******************************@40tude.net. ..
Is there any way to split all merged words but www and e-mail addresses?

I have regexp

preg_replace("/(\.)([[:alpha:]])/", "\\1 \\2", "www.google.com
any,merged.words my****@domain.com")

it give me incorrect result:
www. google. com any, merged. words mymail@domain. com

i need result
www.google.com any, merged. words my****@domain.com

in my case, all web addresses has www. or http:// in beggining of string
and email of course @ inside string

is it possible to write regexp like this?


No. You would use a lookbehind assertion in instances like these, but the
assertion has to be fixed length. Since a domain name can be of any number
of characters, you can't do it.

What you can do is first search for domain names and email addresses,
replacing them with some placeholders, fix the merged words, then replace
the placeholders again. Example:

function encode($m) { return "###" . base64_encode($m[0]) . "###"; }
function decode($m) { return base64_decode($m[1]); }

$s = "www.google.com any,merged.words my****@domain.com";
$s = preg_replace_callback('/\bwww\.[\w\.]+/', 'encode', $s);
$s = preg_replace_callback('/\b[\w\.]+@[\w\.]+/', 'encode', $s);
$s = preg_replace('/([,.])(\w)/', '\1 \2', $s);
$s = preg_replace_callback('/###(.*?)###/', 'decode', $s);

echo $s;
Jul 17 '05 #2
Dnia Tue, 28 Sep 2004 23:37:13 -0400, Chung Leong napisał(a):

function encode($m) { return "###" . base64_encode($m[0]) . "###"; }
function decode($m) { return base64_decode($m[1]); }

$s = "www.google.com any,merged.words my****@domain.com";
$s = preg_replace_callback('/\bwww\.[\w\.]+/', 'encode', $s);
$s = preg_replace_callback('/\b[\w\.]+@[\w\.]+/', 'encode', $s);
$s = preg_replace('/([,.])(\w)/', '\1 \2', $s);
$s = preg_replace_callback('/###(.*?)###/', 'decode', $s);

echo $s;


Thanks a lot! it is great solution I searched a long time!
Jul 17 '05 #3

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

Similar topics

7
by: RickMuller | last post by:
I'm trying to split a string into pieces on whitespace, but I want to save the whitespace characters rather than discarding them. For example, I want to split the string '1 2' into . I was...
3
by: William Ahern | last post by:
I'm looking for resources on splitting and merging XML trees. Specifically, on methods to pare large XML documents into smaller documents which can be merged later. Off of the top of my head, I...
3
by: gregpinero | last post by:
I'm trying to write a little script that will have a list of word pairs which will loop through that list and replace all instances of each word with the other word. I'm very new to javascript...
7
by: Eric McGraw | last post by:
In Firefox, as in most regular expression engines, the split function works like this: > "His name is <name>. His email address is <email>.".split(/<(.*?)>/) returns so that the text pattern...
7
by: Anat | last post by:
Hi, What regex do I need to split a string, using javascript's split method, into words-array? Splitting accroding to whitespaces only is not enough, I need to split according to whitespace,...
17
by: Qiangning Hong | last post by:
I've got some strings to split. They are main words, but some words are inside a pair of brackets and should be considered as one unit. I prefer to use re.split, but haven't written a working one...
5
by: vonclausowitz | last post by:
Repost from an VB group. Hi All, I'm looking for a way to search for multiple words in a database. There is however one but. The words have to be within a certain range of each other. For...
11
by: elrondrules | last post by:
Hi Am pretty new to python and hence this question.. I have file with an output of a process. I need to search this file one line at a time and my pattern is that I am looking for the lines...
2
by: shadow_ | last post by:
Hi i m new at C and trying to write a parser and a string class. Basicly program will read data from file and splits it into lines then lines to words. i used strtok function for splitting data to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.