Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Modifying a RegEx pattern to work whether or not there is a space between two elements.

Posted on 2016-08-19
2
Medium Priority
?
84 Views
Last Modified: 2016-08-19
I have a regex pattern that picks up on strings containing a number followed by a letter or letters, but I need it to pick up on strings where there is a space between the number and the letters that come after it. My current pattern is this: s*\d{1,3}[A-M]. It will pick up 18ABC but not 18 ABC. I haven't used RegEx for a while and I can't remember how to write that.  I'm working in Excel if that makes a difference.

Thanks!

John
0
Comment
Question by:gabrielPennyback
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Accepted Solution

by:
Russ Suter earned 2000 total points
ID: 41762844
s*\d{1,3}\s*[A-M]

Open in new window

will give you a match if there is ANY whitespace between the numbers and letters
s*\d{1,3}\s{0,1}[A-M]

Open in new window

will give you a match if there are exactly zero or one whitespace characters between the numbers and letters

If you're specifically looking for the space character (ascii value 32) and not any whitespace (which can include tabs, new lines, or other whitespace depending on regex options) then you could do this:
s*\d{1,3}[ ]{0,1}[A-M]

Open in new window

Or even more explicitly, call out the octal ASCII value of the space character like this:
s*\d{1,3}\40{0,1}[A-M]

Open in new window

I could probably keep coming up with variants that would serve your needs. Regex is extremely flexible. Let me know if you need more than above.

By the way, the Regex you provided would only match "18A" on the string "18ABC". It would not match "18ABC". For that you'd need to include a trailing asterisk which means [zero or more repetitions].
0
 
LVL 1

Author Comment

by:gabrielPennyback
ID: 41762978
That does it, Russ, thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question