9 Replies - 676 Views - Last Post: 01 April 2013 - 11:32 AM Rate Topic: -----

#1 regex  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 33
  • Joined: 25-September 12

Regex Pattern

Posted 29 March 2013 - 02:58 PM

Have this RegEx Pattern:

\b[0-9](\w*)f\b


I'd like to match any block of text/words that come after this match. For example, if a page displays "124F Feature", I'd like the regex to also match the 'Feature' word.

I'm implementing this in C#. I tried GsSkinner's RegEx tool and it helped but after hacking away at it for 30 minutes I have no solution.

Thanks :)

Is This A Good Question/Topic? 0
  • +

Replies To: Regex Pattern

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3818
  • View blog
  • Posts: 13,534
  • Joined: 12-December 12

Re: Regex Pattern

Posted 29 March 2013 - 03:07 PM

124F Feature

You want the word that follows the space..?

\b[0-9]+F\s?(\w*)\b
Was This Post Helpful? 0
  • +
  • -

#3 regex  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 33
  • Joined: 25-September 12

Re: Regex Pattern

Posted 29 March 2013 - 04:40 PM

I want the word that comes both before and after actually. I took a look at the problem again. Yes, follows the space!

Stored in an array, IList, or whatever.

This post has been edited by regex: 29 March 2013 - 04:40 PM

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3818
  • View blog
  • Posts: 13,534
  • Joined: 12-December 12

Re: Regex Pattern

Posted 29 March 2013 - 04:59 PM

View Postregex, on 29 March 2013 - 11:40 PM, said:

I want the word that comes both before and after actually. I took a look at the problem again. Yes, follows the space!

Stored in an array, IList, or whatever.

The word before what? It would help if you provided a sample phrase to search. I assume you mean the word before 124F, perhaps separated by a space, but it is up to you to make this clear.

\b(\w+)\s?[0-9]+F\s?(\w+)\b
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3818
  • View blog
  • Posts: 13,534
  • Joined: 12-December 12

Re: Regex Pattern

Posted 29 March 2013 - 05:10 PM

View Postregex, on 29 March 2013 - 09:58 PM, said:

I tried GsSkinner's RegEx tool and it helped but after hacking away at it for 30 minutes I have no solution.

hacking away.. are you not studying this subject? Otherwise your username seems inappropriate.

I realise that regex can be a complex/confusing subject, but your studies can be focussed as you have a specific goal to achieve. (This is actually a good way to learn about regex.)
Was This Post Helpful? 0
  • +
  • -

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: Regex Pattern

Posted 29 March 2013 - 05:50 PM

You do know that there are tools and programs that make developing regex simpler?
For example: Expresso

This post has been edited by AdamSpeight2008: 29 March 2013 - 05:52 PM

Was This Post Helpful? 1
  • +
  • -

#7 regex  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 33
  • Joined: 25-September 12

Re: Regex Pattern

Posted 01 April 2013 - 10:39 AM

Need to match:

String: 23F Type
Match: Everything EXCEPT any character that comes after the first numbers.

I am using C#. I am trying to get Gender from this string. I need to only match numbers within the first word in this string, white spaces, and the second word. ONLY allow non-numeric charecters within the first word.

input = Regex.Replace(instance.Text, @"\b(\w*)\b$", String.Empty, RegexOptions.IgnoreCase);

Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3818
  • View blog
  • Posts: 13,534
  • Joined: 12-December 12

Re: Regex Pattern

Posted 01 April 2013 - 10:55 AM

View Postregex, on 01 April 2013 - 05:39 PM, said:

Need to match:

String: 23F Type
Match: Everything EXCEPT any character that comes after the first numbers.

I am using C#. I am trying to get Gender from this string. I need to only match numbers within the first word in this string, white spaces, and the second word. ONLY allow non-numeric charecters within the first word.

input = Regex.Replace(instance.Text, @"\b(\w*)\b$", String.Empty, RegexOptions.IgnoreCase);

You description is confusing: are you trying to replace/remove the letter F that follows the numbers? And do the numbers occur at the beginning of the string?
Was This Post Helpful? 0
  • +
  • -

#9 regex  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 33
  • Joined: 25-September 12

Re: Regex Pattern

Posted 01 April 2013 - 10:57 AM

The numbers occur at the start of the string.

I am using the Csharp based string.replace() method. I only want the LETTERS within the first word REMAINING. So that I am left with either an F or M or any derivative therein for the gender.

That means REMOVING any number, second word, and white space.

Original: 23F Type
Match: 23 Type
Result after REPLACE Should be: F
Was This Post Helpful? 0
  • +
  • -

#10 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3818
  • View blog
  • Posts: 13,534
  • Joined: 12-December 12

Re: Regex Pattern

Posted 01 April 2013 - 11:32 AM

If you will only be left with F or M (I don't know what derivative you are referring to?) then your approach seems exaggerated, IMO. Use Match (or IsMatch) to confirm that the string contains either an F or M, then just use this result, perhaps assigning "F" or "M" to the string.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1