473,513 Members | 2,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to remove all non-letters

hi,

it's really late and i'm struggling with this one - so any help gratefully
received.

if i have a string how would i strip out all characters except letters
between a-z and A-Z

i presume this would be using preg_grep but not being a regex guru is making
it hard.

would it be something like?
$subject = "abc-d%ef"; // Want i want to get back is 'abcdef'
$pattern = '/[a-zA-Z]*/';
preg_match($pattern, $subject, $matches);
// print_r($matches);

$cleaned_word = matches[0];
thanks,

kev
Apr 10 '06 #1
2 2164

I'd use preg_replace() instead:

$subject = "abc-d%ef"; // Want i want to get back is 'abcdef'

$pattern = '/[^a-zA-Z]*/';
echo preg_replace($pattern, '', $subject);

Cheers,
Mike Youell.

Apr 10 '06 #2
Mike Youell wrote:

I'd use preg_replace() instead:

$subject = "abc-d%ef"; // Want i want to get back is 'abcdef'

$pattern = '/[^a-zA-Z]*/';
echo preg_replace($pattern, '', $subject);

Cheers,
Mike Youell.

Thanks for that.

kev
Apr 10 '06 #3

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

Similar topics

9
30756
by: chris | last post by:
is there a quick and easy way to check a string for non numeric characters ? i have thought of making a routine to check each character to confirm it is 0 - 9 but was wondering if there was a...
5
18864
by: omission9 | last post by:
I have a text file which contains the occasional non-ascii charcter. What is the best way to remove all of these in python?
11
5255
by: lovecreatesbeauty | last post by:
Hello experts, Is const_cast only applied to pointers or references? If I have a constant object, then how can I remove constant attribute from it? #include <vector> #include <string>...
7
11083
by: Zeng | last post by:
Hello, Is there a way to remove all non-digit characters from a string in one call? string.Replace() methods don't allow this. thanks!
2
1881
by: ElGordo | last post by:
I was recently given .Net project files to work on. When I open the Solution file in VS.Net, I always get the message: "The solution appears to be under source control, but its binding...
3
6263
by: craigbennett | last post by:
Hi, I am trying to use std::remove to delete a file and have been encountering some problems. My goal is to pass std::remove a std::string and remove the file of that name, for example. ...
80
7798
by: Andrew R | last post by:
Hi I'm creating a series of forms, each with with around 15-20 text boxes. The text boxes will show data from tables, but are unbound to make them more flexible. I want the form to be used...
2
1211
by: Jarry | last post by:
I was editing a huge XML file that a friend of mine had made and I didn't need some of the tags. WHen I was finished editing it, I realised I had a lot of information between tags, in no man's...
5
16832
by: joe | last post by:
hello i have a databse program that uses char arrays to output data to reports. I would like to remove all invalid characters from the array and replace them with a blank space. I have problems...
3
5240
by: Allen Chen [MSFT] | last post by:
Hi Richard, Quote from Richard================================================== However I also want to be able to remove the panes. I have tried to include this, but find that when I first...
1
7098
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...
0
7521
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...
0
5682
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,...
1
5084
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...
0
4745
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...
0
3232
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...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
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...

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.