473,624 Members | 2,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can somebody help out with RegExps?

Hello together,

I'm having extreme difficulties using RegExps for a specific problem
and would really appreciate any help and hope somebody will read
through my "long" posting...

1.
<?php
// Find all blocks containing the postal code, a minimum of 50
characters and a maximum of 200 characters before and after.
//This should me all blocks containing postal code and city.

$arrParsedBlock s = getDataUsingReg exp("'(.{50,250 })".preg_quote( $arrDaten['Plz'])."\s+".preg_qu ote($arrDaten['Ort'])."(.{50,250} )
'is",$content) ;

function getDataUsingReg exp($strRegexp, $string)
{
global $arrDaten;

preg_match_all( $strRegexp, $string, $matches);

$arrListe = array();

for ($i=0; $i< count($matches[0]); $i++)
{
$strData = trim($matches[1][$i].$arrDaten['Plz']."
".$arrDaten['Ort'].$matches[2][$i]);

$arrListe[] = $strData;
}

return $arrListe;
?>

Question:
---------
* How can I extract 3 lines before and after postal code + city?
(instead of a specific number of characters)
2.
<?php
$string = "Kontakt
<br>
Bill Jones

Dr. Bill
Jones<br>
Internet & Webdesign<br>

Examplestreet 9<br>
87354 Munich<br>
Germany<br>
Tel. (0 8 9) 1234 <br>
Handy (0173) 111 <br>
Internet: http://www.foo.com<br>

E-Mail: in**@foo.com";

echo $string;

$output_array = getDataUsingReg exp('#Tel(.*?)< br>#m',$string) ;
var_dump($outpu t_array);

$output_array = getDataUsingReg exp('#Handy(.*? )<br>#m',$strin g);
var_dump($outpu t_array);
?>
Questions:
------------
* I want to extract following data out of a string into an assoziative
array (see above example) e.g.

Array( [Name] => "Bill Jones Dr. Bill Jone"s [Company Name] =>
"Internet & Webdesign" [Street] => "Examplestr eet 9" [City] =>
"87354 Munich" [Country] => "Germany" [Tel] => "(0 8 9) 1234
<br>")

* As a basis I can use a postal code and the city name, with which I
extracted the blocks containing these in step one.

Lines with a telephone number can be identified including words such
as telefon, tel., fon or telephone.

Lines with a fax number can be identified including words such as fax
or telefax.

Lines with a cellural number can be identified including words such as
handy or mobile.

The patterns in my above example are actually very specific and
designed for special cases and are not global at all.

The line above the line holding postal code and city is assumed
holding the street data.

The 2 lines above the line holding the street data are assumed holding
the company name.

Lines between postal code+city and tel. are assumed holding the
country name, where as this is optional. Sometimes there may not even
be any country information available.

I define the separation of lines not only by the separator new line
(/n or <br>) but also strings/characters such as <br> or , or - or :
or ; or |
Since an address can be written in one line, like

Bill Jones | Internet & Webdesign | Examplestreet 9 | 87354 Munich |

1. Company Name
2. Company Name
3. Street Name
3. Postal Code + City name
4. Country Name (optional)
5. Tel.
6. Fax.
7. Handy

5. to 7. can of course differ in order

=> Somehow all sounds simple, but performing a regular expression
pattern is another side of the story... :(

Is there any RegExp professionell out there who could help out? I
would also appreciate detailed explanations, since I'm here to learn!

Thanks a lot!
Rania
Jul 17 '05 #1
0 1577

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

Similar topics

2
8271
by: martijn | last post by:
Hi There, my vb app can open files. Well, actually my vb app launches word or excell to open them. These files are shared in a network. If somebody else has allready opened that file, you must get a requester that says the file is temporarily unavaillable because it is edited somewere else.
5
1653
by: Klaus Alexander Seistrup | last post by:
Hi, Is there a way to "expand" simple regexps? Something along the lines of: #v+ >>> rx = '(a|b)c?(d|f)' >>> expand_regexp(rx)
4
1913
by: Magnus Lie Hetland | last post by:
Hi! I've been looking at ways of dealing with nested structures in regexps (becuase I figured that would be faster than the Python parsing code I've currently got) and came across a few interesting things... First there is this, mentioning the (?<DEPTH>) and (?<-DEPTH>) constructs of the .NET regexp matcher: http://www.rassoc.com/gregr/weblog/archive.aspx?post=590
6
1926
by: lostinspace | last post by:
After four+ years of using FrontPage in a limited capacity and having created over 600 pages on my sites, I've finally (at least for the most part) abandoned FP, to begin the process of converting those pages. There are some things (a result of this transition,) which I'm not too happy about :-( I'm using 1st Page 2000. Much of my content is created in Word and then cut and pasted from Word-to-NotePad-to-the page. Formerly with FP the...
4
3093
by: possibilitybox | last post by:
I'm trying to make a unicode friendly regexp to grab sentences reasonably reliably for as many unicode languages as possible, focusing on european languages first, hence it'd be useful to be able to refer to any uppercase unicode character instead of just the typical , which doesn't include, for example É. Is there a way to do this, or do I have to stick with using the isupper method of the string class?
2
3033
by: Yorian | last post by:
I just started to try regexps in php and I didn't have too many problems, however I found a few when trying to build a templte engine. The first one is found is the dollar sign. In my template I would like to write this: {$var} where var ofcourse will be replaced by the real var however I'm having trouble with the dollar sign I do escape the it though, my regexp:
3
1831
by: lagu2653 via DotNetMonster.com | last post by:
I have a log-in window application. When the user presses the cancel button it kills another window by it's name and then it exits. The problem is that if somebody kills the log-in window by terminating the process in the task manager the other window is not killed. One solution might be to have a surveillande thread which doesn't die when the mother-thread dies, and can't be killed in the task manager. As soon as the log-in window...
5
1720
by: Sunfire | last post by:
Can somebody put this code into c#? Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim imageFolder As String Dim imageText As String Dim bm As Bitmap Dim ms As MemoryStream imageFolder = Request.QueryString(imFolder)
9
3185
by: ahilar12 | last post by:
1. <head> 2. <script type="text/javascript"> 3. </script> 4. </head> 5. <body> 6. <form> 7. <select name="team" id="mylist" > 8. <option></option> 9. <option>north</option> 10. <option>south</option>
0
8246
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
8179
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
8685
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...
1
8341
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,...
1
6112
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
5570
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
4084
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...
0
4184
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1489
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.