AutoHotkey Community

It is currently May 27th, 2012, 8:23 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: February 4th, 2012, 6:36 am 
Offline

Joined: August 30th, 2007, 9:36 pm
Posts: 90
Hi,

I'm trying to remove any numbers from a phrase unless the number is in words, but not sure how to do this with RegExMatch

for example if my variable was this:
var = I really love my BCM100CM 15 watt Speaker

I would like to only pull out the numbers 15 because there are no words connected to it. So what I would like matched would look something like this:

I love my BCM100CM watt speaker

How would I go about doing this?

Thanks
Chip


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2012, 6:48 am 
Code:
var = I really love my BCM100CM 15 watt Speaker
newstring := regexreplace(var, "\s\K(\d+\s)")
msgbox % newstring


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2012, 7:28 am 
Offline

Joined: August 30th, 2007, 9:36 pm
Posts: 90
Hi Thanks so much, that worked,

Now what does the \K mean?

also how would I do this if I wanted to only remove the words connected to a number (in example, remove BCM100CM) so the output would look like:

I really love my 15 watt Speaker


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2012, 7:43 am 
chipmanners wrote:
Now what does the \K mean?
the manual wrote:
The escape sequence \K is similar to a look-behind assertion because it causes any previously-matched characters to be omitted from the final matched string. For example, foo\Kbar matches "foobar" but reports that it has matched "bar".


Quote:
how would I do this if I wanted to only remove the words connected to a number (in example, remove BCM100CM) so the output would look like:

I really love my 15 watt Speaker
Code:
var = I really love my BCM100CM 15 watt Speaker
newstring := regexreplace(var, "\s\K\w+\d+\w+\s")
msgbox % newstring


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2012, 5:00 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5482
Location: the tunnel(?=light)
Guest wrote:
Code:
var = I really love my BCM100CM 15 watt Speaker
newstring := regexreplace(var, "\s\K(\d+\s)")
msgbox % newstring


That doesn't quite get all instances:

Code:
var = I really love my BCM100CM 15 watt Speaker
newstring := regexreplace(var, "\b\d+\b | \b\d+\b")
msgbox % newstring

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, hyper_, immunity, migz99, sjc1000 and 72 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group