2

I have an address like

New street 4 
462005 MG Road 
Tel .: 02281 / 93-1-212  
Fax .: 02681 / 93-1148

I want string before "Tel" and remove whatever comes after "Tel"

New street 4 
462005 MG Road 

What i have tried is

(?!^Tel$)(^.*$)

But its only gives first line. New street 4

How can be achieve this using regular expression without any PHP function.

2
  • Oh, without any PHP function.. missed that important update. Commented Dec 29, 2015 at 13:37
  • @Adas Please notice that I updated my answer so you won't get screwed when a street name includes the string Tel. Commented Dec 29, 2015 at 13:39

3 Answers 3

1

Make sure to activate single line mode:

(?s).*?(?=Tel)

Demo: https://regex101.com/r/dX7kU7/1

edit:
A little improvement: this updated version should be a tad more robust and stop when a new line starts with Tel, i.e. you won't get screwed when a street name includes the substring Tel: https://regex101.com/r/dX7kU7/2

Sign up to request clarification or add additional context in comments.

2 Comments

Bingo...exactly what i need. thank you very much @timgeb
@Adas no problem, happy coding
0

This should do the trick

Replace

([\s\S]*?)(Tel[\s\S]*)

With

$1

1 Comment

It gives with Tel, and i don't want that, i want only first two lines of address.
0

Be original! )))

if (false !== $pos = strpos($str, 'Tel')) {
    $str = substr($str, 0, $pos);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.