473,766 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.word s my****@domain.c om")

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.c om

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 2431

"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.word s my****@domain.c om")

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.c om

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.word s my****@domain.c om";
$s = preg_replace_ca llback('/\bwww\.[\w\.]+/', 'encode', $s);
$s = preg_replace_ca llback('/\b[\w\.]+@[\w\.]+/', 'encode', $s);
$s = preg_replace('/([,.])(\w)/', '\1 \2', $s);
$s = preg_replace_ca llback('/###(.*?)###/', '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.word s my****@domain.c om";
$s = preg_replace_ca llback('/\bwww\.[\w\.]+/', 'encode', $s);
$s = preg_replace_ca llback('/\b[\w\.]+@[\w\.]+/', 'encode', $s);
$s = preg_replace('/([,.])(\w)/', '\1 \2', $s);
$s = preg_replace_ca llback('/###(.*?)###/', '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
1153
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 certain that there was a way to do this using the standard string functions, but I just spent some time poring over the documentation without finding anything. There's a chance I was instead thinking of something in the re module, but I also...
3
2539
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 can envision unions of node sets, and unions of node text. But I know there's much more to the subject than that, if not more alternatives than greater technical detail. TIA,
3
8893
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 so I'm not quite sure where to get started. Here is my python "prototype" in case you want a better idea of what I'm trying to do: <code> corpus="""
7
2097
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 in the parentheses is included in the result. In Internet Explorer, however, the result is different:
7
25791
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, comma, hyphen, etc... Is there a regex that does the trick? Thanks, Anat.
17
8209
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 after hours of work. Example: "a (b c) d h i" should be splitted to ", "h", "i"]
5
5057
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 example I would like to find records which contain the word MALE and within for example 10 words of it the word BROWN.
11
11822
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 that has the word 'event' and the word 'new'. Note that i need lines that has both the words only and not either one of them..
2
3270
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 lines it worked quite well but srttok isnot working for multiple blank or commas. Can strtok do this kind of splitting if it cant what should i use . Unal
0
9571
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
10168
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
10009
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
9959
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
9838
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7381
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
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3929
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
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.