473,887 Members | 2,286 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 2437

"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
1157
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
2545
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
8903
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
2101
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
25795
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
8226
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
5066
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
11836
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
3283
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
9957
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
9799
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10771
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
10877
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
9593
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7988
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
7143
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6011
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4633
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

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.