Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Help pls: Search for 3 characters then trim 8 characters from right



  • Please log in to reply
6 replies to this topic
radiosilk
  • Members
  • 22 posts
  • Last active: Nov 06 2015 09:10 AM
  • Joined: 27 Sep 2015

My apologies if i have not been able to explain this in easy terms.

 

What i have text on clipboard that has columns and rows of text-data. Target is fix --> column1. (tabs are used to separate columns)

 

What we know is: the 3 characters we are looking for will always be the rightmost of text in that column, if they are present at all.

(Those 3 characters are "FUT")

 

What is needed is: If "FUT" is found in column1 row1, then TRIM 8 characters from right. (includes trimming off of "FUT" as well).

 

Now, i  know how to look for "FUT" and how to replace it. BUT, don't know how to look for "FUT" and trim "FUT" and 5 more characters along with it

 

Please help..



Masonjar13
  • Members
  • 1517 posts
  • Last active:
  • Joined: 16 Sep 2012

Here's a start, but you'll have to change it to accomodate for only finding the one in column1, row 1. I can't, because I have no reference.

clipboard:=regExReplace(clipboard,"FUT.....",,,1)

OS: Windows 7 Ultimate / Windows 8.1 Pro | Editor: Notepad++


radiosilk
  • Members
  • 22 posts
  • Last active: Nov 06 2015 09:10 AM
  • Joined: 27 Sep 2015

Hi, thanks for replying.

 

I went through RegExReplace() help content. Using the terminology of AutoHotkey Help content to describe the issue.

 

The issue is that "Haystack" itself is not always fixed. "Haystack" always is of 8 characters. The last 3 characters of which are "FUT". But other 5 on the left of "FUT" change frequently.

 

We can completely do away with this "haystack" by identifying the "static" part of "haystack" which is "FUT". 

 

BUT, i don't know how to define this "haystack" because it has 5 characters that keep changing.

 

Here, let me give an example:

 

Haystack1: "13JANFUT"

Haystack2: "15JULFUT"

Haystack3: "21JUNFUT"

 

The last 3 characters "FUT" are fixed always. But not 5 before FUT.

 

AND we need to remove entire 8 characters.



radiosilk
  • Members
  • 22 posts
  • Last active: Nov 06 2015 09:10 AM
  • Joined: 27 Sep 2015
How to make this work ?
 
yr:="15" or "16" or "17" or "18" or "19" or "20"
mnth:="JAN" or "FEB" OR "MAR" OR "APR" OR "MAY" OR "JUN" OR "JUL" OR "AUG" OR "SEP" OR "OCT" OR "NOV" OR "DEC"
iffut:=%yr% %mnth% "FUT"

IfInString,dato,%iffut%
{
     StringReplace, dato, dato, %iffut%, , All
}


Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

Try this approach:

 

string:="TESTINGTHISFUT"
IfInString, string, FUT
StringTrimRight, string, string, 8
MsgBox %string%
return


radiosilk
  • Members
  • 22 posts
  • Last active: Nov 06 2015 09:10 AM
  • Joined: 27 Sep 2015
The problem is how to define that string?? 
You have assumed that "TESTINGTHISFUT" is what "haystack" is. NO.
 
My haystack is like..
 
string:="xxxxxFUT"
 
where x can take values from 0to9 and AtoZ
 
Here, let me give an example:
 
Haystack1: "13JANFUT"
Haystack2: "15JULFUT"
Haystack3: "21JUNFUT"
 
So, how do i define that string ?


radiosilk
  • Members
  • 22 posts
  • Last active: Nov 06 2015 09:10 AM
  • Joined: 27 Sep 2015
✓  Best Answer

got this working answer from another post. Just so that it helps others.

 

Thank you for giving time and efforts in helping..

;code by Jackie

regex_patten = \d{2}[a-zA-Z]{3}FUT
 
if RegExMatch(string, regex_patten)
newstring := RegExReplace(string, regex_patten, "")
 
msgbox % "old string:`n`n" string "`n`nnew string`n`n" newstring