473,394 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Help regarding Regular Expression

296 100+
I have a string like -->
23232006-23-2323:12:12dsds-we-ew:wes.doc

I want a regex which can remove the : and - only in the numerical part like -->
232320062323231212dsds-we-ew:wes.doc
Dec 29 '06 #1
3 1217
pankajit09
296 100+
to make ur work easy I want the regex to have effeect only till first 22 places for eg:- 23232323-23-2312:23:23ewew-sds-wew-wew.doc

the numerical part is always fixed for 22 places.
Dec 29 '06 #2
pankajit09
296 100+
ok no need to think .

I got the solution -->

Expand|Select|Wrap|Line Numbers
  1. substr($expr,0,22) =~ s/[:-]//g; 
Dec 29 '06 #3
miller
1,089 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. substr($expr,0,22) =~ s/[:-]//g; 
That is a very elegant solution. I've never actually seen substr used as an lvalue in quite that way before, so I'm glad that you posted your question. You could simplify the regex slightly by removing any non-digits instead of explicitly specifying [:-]

Expand|Select|Wrap|Line Numbers
  1. substr($expr,0,22) =~ s/\D//g;
  2.  
Alternatively, I was going to suggest that you use lookahead and lookbehind assertions, but your method is much clearer given your expanded specification. Nevertheless, an alternative method:

Expand|Select|Wrap|Line Numbers
  1. $expr =~ s/(?<=\d)\D(?=\d)//g;
  2.  
Dec 29 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Steve | last post by:
Hello, I am writing a script that calls a URL and reads the resulting HTML into a function that strips out everthing and returns ONLY the links, this is so that I can build a link index of various...
1
by: Mosas | last post by:
Dear All In Perl when we are checking some conditions using regular expression we can ignore the case sensitive of a string using the following regular expression /(^)|/|(\.\.)/i. But If I try...
5
by: Bradley Plett | last post by:
I'm hopeless at regular expressions (I just don't use them often enough to gain/maintain knowledge), but I need one now and am looking for help. I need to parse through a document to find a URL,...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
3
by: Joe | last post by:
Hi, I have been using a regular expression that I don’t uite understand to filter the valid email address. My regular expression is as follows: <asp:RegularExpressionValidator...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
3
by: Zach | last post by:
Hello, Please forgive if this is not the most appropriate newsgroup for this question. Unfortunately I didn't find a newsgroup specific to regular expressions. I have the following regular...
5
by: John | last post by:
Hi I am using RegularExpressionValidator. What expression do I need to validate these two; Field1: A9 9AA A99 9AA A9A 9AA
3
by: Mr.Steskal | last post by:
Posted: Wed Jul 11, 2007 7:01 am Post subject: Regular Expression Help -------------------------------------------------------------------------------- I need help writing a regular...
1
by: sunil | last post by:
Hi, Am writing one C program for one of my module and facing one problem with the regular expression functions provided by the library libgen.h in solaris. In this library we are having two...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.