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

Regular expression for capturing the first alpha string in a document

Hi,

I need a regular expression for capturing the first alpha string in a document not necessarily on the first line

match first instance

Here is a few tried permutations

Expand|Select|Wrap|Line Numbers
  1. [:alpha:]*
  2.  
  3. [:alpha:]*.[:alpha:]*
  4.  
  5. [A-Z][a-z]*.[A-Z][a-z]*\r
  6.  
  7.  
May 12 '11 #1

✓ answered by Rabbit

Turns out you can just use [a-zA-z][^\n]* and if you have global turned off, it'll return the first result and if you have global turned on, you just need the first result.

9 3587
Rabbit
12,516 Expert Mod 8TB
It would help to see some example inputs and expected results.
May 12 '11 #2
Hi,

Here is an example document. I only want the first string in the document captured - nothing else. Note the First string could be more than two words in mix case. The end of line does not work for me

Expand|Select|Wrap|Line Numbers
  1. %20
  2. Banff Springs
  3. Banff Sprints Hotel
  4. %20
  5. Mountain Biking 34.78
  6. %20
  7. Table # 55  holiday forward
  8. $1,899,999.00
  9.  
  10. 55555
  11. Togo Hot Specials
  12.  
May 12 '11 #3
Rabbit
12,516 Expert Mod 8TB
So in that example you just want the word Banff? We also need to know what language you're programming in or which regex engine you're using.
May 12 '11 #4
JRegex is fine.

I need to capture the title beit on the first line, second or third after a single return char or multiple. So if there are three blank lines and then text that is to be assumed the title and all the text on that line is required. In this example it would be Banff Springs.

Thanks for you help
May 16 '11 #5
Rabbit
12,516 Expert Mod 8TB
Well, assuming multiline is turned on then the regex you would use is "[^\w]*\w[^\n]*" So basically, any number of non-alphabet characters followed by an alphabet character followed by any number of non-new line characters.
May 24 '11 #6
The first line is now being captured as the first hit in the test-text area of QuickREx. The other text below is also matching as secondary.(in yellow) if you are farmilar with QuickREx. I tried to include a line brake so that it would only highlight the first instance, being the title but it doesn't seem to work.

Is there an option so that only the first instance is captured? Like, read all information until end of line and nothing else?

Thanks for your help!
May 25 '11 #7
Rabbit
12,516 Expert Mod 8TB
Turns out you can just use [a-zA-z][^\n]* and if you have global turned off, it'll return the first result and if you have global turned on, you just need the first result.
May 25 '11 #8
Thanks for your help Dr. Rabbit

Appreciate the assistance!
May 25 '11 #9
rampdv
7
Hi keydrive
Here i provide the solution to u r example document using regular expression in perl.
Here i read a file data word by word and push that data into array and print the first value of the array

if u have any doubts or find any error in code please make a follow up
Expand|Select|Wrap|Line Numbers
  1. open(alpha,"alphastring.txt");
  2.  
  3. while(<alpha>){
  4.  
  5. while($_ =~ /([a-zA-Z]+)/ig) {
  6.  
  7. push @array,$1;
  8.  
  9. }
  10.  
  11. }
  12. print " $array[0] \n";
  13.  
  14.  
Mar 5 '13 #10

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

Similar topics

6
by: Matt | last post by:
I want to check if the user enters alphabet or numbers only in the text box. If the user enters non-alphabet or non-numbers, I should pop up a message and doesn't allow the user to do that. I am...
2
by: Robin Tucker | last post by:
Hiya, Regular expressions always do my gnads in - can anyone cook up a reg expression to find all string literals in my code? I would like to put them into a resource file for future...
1
by: guozhen | last post by:
hey.I got a problem I want to parse the string below with regular expression ¡°1¡¢¾«Í¨»ùÓÚJ2EE¼Ü¹¹µÄJavaºËÐÄÓï·¨¡¢Java±à³Ì£¬3ÄêÒÔÉÏÈí¼þ¿ª·¢»òÅàѵÏà¹Ø ¹¤×÷¾­ÑéÕߣ»<?xml:namespace prefix = o ns =...
6
by: =?Utf-8?B?QmlsbEF0V29yaw==?= | last post by:
Hi, Thought this would be simple! If I want to validate a field that can contain "z" followed by 3 digits OR it's a completely empty string, how do I do that? The z123 bit is simple, but the empty...
8
by: .Net Sports | last post by:
I am checking for text input on a form validation in javascript that required at least one numeric character along with any number of alpha characters for a given input text box. The below is a var...
1
by: st12iker | last post by:
Im looking for a regex expression that would enable me to match a pattern only before the first \n of a line. So for example if I had text if $\ = $$ and had text 123 DFG\n (1st line) $$ 345\n...
1
by: pnsreee | last post by:
Hi I have following strings Sun:mon:tue mon:tue:wed mon:wed:mon I need to check the string have valid values sun,mon,tue,wed and also check duplicates are there or not
1
by: sreemathy2000 | last post by:
My requirement is to read/write a javascript file in a windows applications. this javascript file is used by my website.. function test { var a; //start dim obj ={'abc','bcd','cde','def'};...
2
by: Gabriela | last post by:
Hi, I need help with writing a regexp that identifies HTML encoded strings. The problem occurred because I have a field in the DB, that contains regular ASCII chars, as well as HTMLencoded...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.