473,387 Members | 1,517 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,387 software developers and data experts.

Regex - Capturing before pattern

hi,

im totally new to perl prgramming and am praying aloud for some help. When using a regular expression to find certain character in text, how can i backtrack and take the first 250 letters before the script encountered the specific character, and also the 250 characters in data after script encountered the specific charater. Any feedback will be appreciated. Thanks for any help in advance!
Aug 22 '07 #1
4 1307
miller
1,089 Expert 1GB
Don't make it a backtrack. Just match what you want.

Expand|Select|Wrap|Line Numbers
  1. if ($text =~ m{(.{250})your special character here(.{250})}s) {
  2.     print "Pre = $1\n";
  3.     print "Post = $2\n";
  4. }
  5.  
- Miller
Aug 22 '07 #2
numberwhun
3,509 Expert Mod 2GB
Hey Miller!

Welcome back. I sent you a PM when you get a chance.

Regards,

Jeff
Aug 22 '07 #3
miller
1,089 Expert 1GB
Thanks Jeff

Yeah, I should get to my messages some time this afternoon. Got a lot of catching up to do, but I feel like I'm on a roll so shouldn't have too much trouble.

- Miller
Aug 22 '07 #4
numberwhun
3,509 Expert Mod 2GB
No worries! I understand the "being on a roll thing" and having to catch up. Take your time. Good to see you back online!

Jeff
Aug 22 '07 #5

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

Similar topics

3
by: Online | last post by:
Hello, This code: <?php preg_replace_callback("/(a)|(b)/", create_function('$x', 'foreach ($x as $y => $z)'. 'echo "\\\$y: $z<br>";'), "b");
5
by: Andrew Dixon | last post by:
Hi Everyone. Ok I have a problem getting the following regex to work in Java. <script*>(.|\r|\n)+?</script> It works fine in EditPad Pro but in Java it causes the following error message...
75
by: Xah Lee | last post by:
http://python.org/doc/2.4.1/lib/module-re.html http://python.org/doc/2.4.1/lib/node114.html --------- QUOTE The module defines several functions, constants, and an exception. Some of the...
5
by: Bill Cohagan | last post by:
I'm looking for help with a regular expression question, so my first question is which newsgroup is the best one to post to? Just in case *this* is the best choice, here's the problem: I'm...
2
by: Frank Oquendo | last post by:
I have the following code: string pattern = @"(\{)|(})|(\()|(\))|(\)|(\^)|(\*)|(/)|(-)|(\+)|(%)"; Regex regex = new Regex(pattern); string input = "QTY * ESTIMATED COST + 2"; string tokens =...
7
by: lgbjr | last post by:
Hi All, I'm trying to split a string on every character. The string happens to be a representation of a hex number. So, my regex expression is (). Seems simple, but for some reason, I'm not...
17
by: Mark | last post by:
I must create a routine that finds tokens in small, arbitrary VB code snippets. For example, it might have to find all occurrences of {Formula} I was thinking that using regular expressions...
7
by: jaylucier | last post by:
Howdy, I'm trying to break an input string into multpile pieces using a series of delimiters that start with an asterisk. Following the asterisk is a mulitple character identifier immediately...
6
by: ffreino | last post by:
Hi, I'm trying to capture text between two words in a multi-line string. For example: 89. This is the text I would like to capture. This is another line. 90. End of the example. I would like...
2
by: GS | last post by:
How can one avoid capturing leading empty or blank lines? the data I deal with look like this "will be paid on the dates you specified. xyz supplier amount: $100.52 when: September 07,...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.