BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
YannRC
Quartz | Level 8

Hi,

I am a beginner in Regex and it's very difficult to understand some errors. I want to find 30 kms or 30 km, or 30 kilometers 

REGEX: [0-9][0-9] km(s)?. 
I Try with that only for km or kms but I have always a error with a escape character and I don't understand when I have to add this one.
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
And could try this:
REGEX: [0-9][0-9] kms?
If you need to match dot ,you need to add escape char '\':
REGEX: [0-9][0-9] kms?\.

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

Can you provide more details of what you have tried?
Are you trying to write CODE?  If so show the code.  Provide some example input data and the expected result.

Are you trying to use REGEX is some other place? Explain where.  

Be specific about the environment you are using and the version of SAS you are using and version of any front end tools like Enterprise Guide or SAS/Studio.

Ksharp
Super User

Add some sample data would be very helpful to understand your question.

Here you go.

data x;
input x $80.;
if prxmatch('/\d+\s*(km|kms|kilometers)/i',x) then match=1;
 else match=0;
cards;
I want to find 30 kms 
I want to find 30 km, 
I want to find 30 kilometers 
I want to find kilometers 
;




Ksharp_0-1768271850308.png

 

Ksharp
Super User
And could try this:
REGEX: [0-9][0-9] kms?
If you need to match dot ,you need to add escape char '\':
REGEX: [0-9][0-9] kms?\.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

Register now

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 121 views
  • 0 likes
  • 3 in conversation