- 12-08-16
12-08-16
12-08-16
12-08-16
DL10587
DL10575
DL11318
DL2514
DL8526
DL36521
DL7485
70,000.00
14,700.00
3,000.00
How to remove specific values from clipboard?
- Sabestian Caine
- Posts: 528
- Joined: 12 Apr 2015, 03:53
How to remove specific values from clipboard?
Friends I want that specific values should be removed from the copied data (clipboard). For example I have following data in clipboard-
I don't normally code as I don't code normally.
-
- Posts: 1259
- Joined: 16 Apr 2015, 09:41
Re: How to remove specific values from clipboard?
Code: Select all
F1::
Clipboard := Trim(RegExReplace(Clipboard, "m)^(\d\d-\d\d-\d\d)$|^(D[^\d]?\d*)$", ""), " `r`n`t") ; This will work even if the dates change.
Return
- Sabestian Caine
- Posts: 528
- Joined: 12 Apr 2015, 03:53
Re: How to remove specific values from clipboard?
Thanks dear Shadowpheonix the codes suggested by you are working as i want exactly ....you are really great at ahk.....i appreciate your skills and abilities.....thanks a lot once again....Shadowpheonix wrote:Code: Select all
F1:: Clipboard := Trim(RegExReplace(Clipboard, "m)^(\d\d-\d\d-\d\d)$|^(D[^\d]?\d*)$", ""), " `r`n`t") ; This will work even if the dates change. Return
I don't normally code as I don't code normally.
- Sabestian Caine
- Posts: 528
- Joined: 12 Apr 2015, 03:53
Re: How to remove specific values from clipboard?
Dear shadowpheonix...could you please make me understand why these codes have been used like this here. I tried to read the documentation part of RegExReplace but i could not understand much. i request you to make me understand few of these symbols from above codes-Shadowpheonix wrote:Code: Select all
F1:: Clipboard := Trim(RegExReplace(Clipboard, "m)^(\d\d-\d\d-\d\d)$|^(D[^\d]?\d*)$", ""), " `r`n`t") ; This will work even if the dates change. Return
Code: Select all
clipboard - is haystack i.e. whose content is to be processed, as far as i know
"m - as far as i read the documentation part "m means haystack is multi line. Please tell me more about using "m in RegExReplace command
^ - as far as i know this symbol is used to combine two statements and is used at the beginning. please elaborate this symbol
\d\d - as far as i read the documentation part \d is used to match any single digit. but here you used three sets of \d\d i dont know why you used three sets of \d\d please tell me.
$ - this sign is used at the end of line. kindly elaborate this sign
| - i dont know about this sign
D - again you used capital D i do not know why. i think it is to remove alphanumeric values which starts from letter D. please tell me more about this.
? - as far as i read the documentation part, A question mark matches zero or one of the preceding character, please tell me why this has been used here.
and what is the mean of these symbols- \d*)$", ""), " `r`n`t")
please help me understand these symbols and tell me why they have been used here in this particular sequence.
I will be highly obliged to you.
many many thanks to you..
I don't normally code as I don't code normally.
-
- Posts: 1259
- Joined: 16 Apr 2015, 09:41
Re: How to remove specific values from clipboard?
Here is a breakdown of the m)^(\d\d-\d\d-\d\d)$|^(D[^\d]?\d*)$ portion of the RegEx I provided you...Sabestian Caine wrote:Dear shadowpheonix...could you please make me understand why these codes have been used like this here. I tried to read the documentation part of RegExReplace but i could not understand much. i request you to make me understand few of these symbols from above codes-Shadowpheonix wrote:Code: Select all
F1:: Clipboard := Trim(RegExReplace(Clipboard, "m)^(\d\d-\d\d-\d\d)$|^(D[^\d]?\d*)$", ""), " `r`n`t") ; This will work even if the dates change. Return
Code: Select all
clipboard - is haystack i.e. whose content is to be processed, as far as i know "m - as far as i read the documentation part "m means haystack is multi line. Please tell me more about using "m in RegExReplace command ^ - as far as i know this symbol is used to combine two statements and is used at the beginning. please elaborate this symbol \d\d - as far as i read the documentation part \d is used to match any single digit. but here you used three sets of \d\d i dont know why you used three sets of \d\d please tell me. $ - this sign is used at the end of line. kindly elaborate this sign | - i dont know about this sign D - again you used capital D i do not know why. i think it is to remove alphanumeric values which starts from letter D. please tell me more about this. ? - as far as i read the documentation part, A question mark matches zero or one of the preceding character, please tell me why this has been used here. and what is the mean of these symbols- \d*)$", ""), " `r`n`t") please help me understand these symbols and tell me why they have been used here in this particular sequence. I will be highly obliged to you. many many thanks to you..
When used at the very beginning of a RegEx, the ^ represents the beginning of a line.
When used at the very end of a RegEx, the $ represents the end of a line.
Together, these mean that everything in between must match the entire line.
The | character is the pipe symbol, and represents an OR condition, meaning either \d\d-\d\d-\d\d or D[\d]?\d* can match.
\d\d-\d\d-\d\d is 2 digits, a dash, 2 digits, a dash, and 2 more digits. IE: It matches 12-08-16.
In the D[\d]?\d* portion, the D is a literal value.
When used inside a RegEx (IE: not at the beginning), ^ represents a NOT condition.
The ? does indeed make the preceeding code match zero or one digit.
Together, these mean [^\d]? represents an optional single character that is NOT a digit.
D[\d]?\d* will match any line starting with D, optionally followed by a single letter, and then by an unlimited number of digits. IE: DL11318, DL2514, D12345678, and DA6 would all match.
The way I interpreted your original post, I got the impression that you had instances where the L was not always present. I guessed (perhaps incorrectly) that it could sometimes be missing completely, or could sometimes be a different single character, so I allowed for that in the RegEx.
Does that help your understanding?
Re: How to remove specific values from clipboard?
Shadowpheonix wrote:Here is a breakdown of the m)^(\d\d-\d\d-\d\d)$|^(D[^\d]?\d*)$ portion of the RegEx I provided you...Sabestian Caine wrote:Dear shadowpheonix...could you please make me understand why these codes have been used like this here. I tried to read the documentation part of RegExReplace but i could not understand much. i request you to make me understand few of these symbols from above codes-Shadowpheonix wrote:Code: Select all
F1:: Clipboard := Trim(RegExReplace(Clipboard, "m)^(\d\d-\d\d-\d\d)$|^(D[^\d]?\d*)$", ""), " `r`n`t") ; This will work even if the dates change. Return
Code: Select all
clipboard - is haystack i.e. whose content is to be processed, as far as i know "m - as far as i read the documentation part "m means haystack is multi line. Please tell me more about using "m in RegExReplace command ^ - as far as i know this symbol is used to combine two statements and is used at the beginning. please elaborate this symbol \d\d - as far as i read the documentation part \d is used to match any single digit. but here you used three sets of \d\d i dont know why you used three sets of \d\d please tell me. $ - this sign is used at the end of line. kindly elaborate this sign | - i dont know about this sign D - again you used capital D i do not know why. i think it is to remove alphanumeric values which starts from letter D. please tell me more about this. ? - as far as i read the documentation part, A question mark matches zero or one of the preceding character, please tell me why this has been used here. and what is the mean of these symbols- \d*)$", ""), " `r`n`t") please help me understand these symbols and tell me why they have been used here in this particular sequence. I will be highly obliged to you. many many thanks to you..
When used at the very beginning of a RegEx, the ^ represents the beginning of a line.
When used at the very end of a RegEx, the $ represents the end of a line.
Together, these mean that everything in between must match the entire line.
The | character is the pipe symbol, and represents an OR condition, meaning either \d\d-\d\d-\d\d or D[\d]?\d* can match.
\d\d-\d\d-\d\d is 2 digits, a dash, 2 digits, a dash, and 2 more digits. IE: It matches 12-08-16.
In the D[\d]?\d* portion, the D is a literal value.
When used inside a RegEx (IE: not at the beginning), ^ represents a NOT condition.
The ? does indeed make the preceeding code match zero or one digit.
Together, these mean [^\d]? represents an optional single character that is NOT a digit.
D[\d]?\d* will match any line starting with D, optionally followed by a single letter, and then by an unlimited number of digits. IE: DL11318, DL2514, D12345678, and DA6 would all match.
The way I interpreted your original post, I got the impression that you had instances where the L was not always present. I guessed (perhaps incorrectly) that it could sometimes be missing completely, or could sometimes be a different single character, so I allowed for that in the RegEx.
Does that help your understanding?
thank you very much dear Shadowpheonix. First time in life i could learn the codes so easily. I highly appreciate your way of making others understand. Really i could learn a lot from your description of codes above. thank you very much again.
Have a whale of time....
- Sabestian Caine
- Posts: 528
- Joined: 12 Apr 2015, 03:53
Re: How to remove specific values from clipboard?
Thanks dear shadowpheonix for making me understand all these things in so easy way.Shadowpheonix wrote:Here is a breakdown of the m)^(\d\d-\d\d-\d\d)$|^(D[^\d]?\d*)$ portion of the RegEx I provided you...Sabestian Caine wrote:Dear shadowpheonix...could you please make me understand why these codes have been used like this here. I tried to read the documentation part of RegExReplace but i could not understand much. i request you to make me understand few of these symbols from above codes-Shadowpheonix wrote:Code: Select all
F1:: Clipboard := Trim(RegExReplace(Clipboard, "m)^(\d\d-\d\d-\d\d)$|^(D[^\d]?\d*)$", ""), " `r`n`t") ; This will work even if the dates change. Return
Code: Select all
clipboard - is haystack i.e. whose content is to be processed, as far as i know "m - as far as i read the documentation part "m means haystack is multi line. Please tell me more about using "m in RegExReplace command ^ - as far as i know this symbol is used to combine two statements and is used at the beginning. please elaborate this symbol \d\d - as far as i read the documentation part \d is used to match any single digit. but here you used three sets of \d\d i dont know why you used three sets of \d\d please tell me. $ - this sign is used at the end of line. kindly elaborate this sign | - i dont know about this sign D - again you used capital D i do not know why. i think it is to remove alphanumeric values which starts from letter D. please tell me more about this. ? - as far as i read the documentation part, A question mark matches zero or one of the preceding character, please tell me why this has been used here. and what is the mean of these symbols- \d*)$", ""), " `r`n`t") please help me understand these symbols and tell me why they have been used here in this particular sequence. I will be highly obliged to you. many many thanks to you..
When used at the very beginning of a RegEx, the ^ represents the beginning of a line.
When used at the very end of a RegEx, the $ represents the end of a line.
Together, these mean that everything in between must match the entire line.
The | character is the pipe symbol, and represents an OR condition, meaning either \d\d-\d\d-\d\d or D[\d]?\d* can match.
\d\d-\d\d-\d\d is 2 digits, a dash, 2 digits, a dash, and 2 more digits. IE: It matches 12-08-16.
In the D[\d]?\d* portion, the D is a literal value.
When used inside a RegEx (IE: not at the beginning), ^ represents a NOT condition.
The ? does indeed make the preceeding code match zero or one digit.
Together, these mean [^\d]? represents an optional single character that is NOT a digit.
D[\d]?\d* will match any line starting with D, optionally followed by a single letter, and then by an unlimited number of digits. IE: DL11318, DL2514, D12345678, and DA6 would all match.
The way I interpreted your original post, I got the impression that you had instances where the L was not always present. I guessed (perhaps incorrectly) that it could sometimes be missing completely, or could sometimes be a different single character, so I allowed for that in the RegEx.
Does that help your understanding?
sir as i want to remove all the numeric digits i.e.
70,000.00
14,700.00
3,000.00
from the above series and want to keep only these values-
12-08-16
12-08-16
12-08-16
12-08-16
DL10587
DL10575
DL11318
DL2514
DL8526
DL36521
DL7485
in the clipboard then what would be the codes?
as i tried to use these codes as you told me in your description but these codes are not working. I know i am making some mistakes in these codes-
Code: Select all
f2::
Clipboard := trim(RegExReplace(Clipboard, "m)^([\d?\d*])$", ""), " `r`n`t")
msgbox % clipboard
return
Code: Select all
f2::
Clipboard := trim(RegExReplace(Clipboard, "m)^(7[\d?\d*])$", ""), " `r`n`t")
msgbox % clipboard
return
thanks a lot sir...
I don't normally code as I don't code normally.
-
- Posts: 1259
- Joined: 16 Apr 2015, 09:41
Re: How to remove specific values from clipboard?
Sabestian Caine wrote:Thanks dear shadowpheonix for making me understand all these things in so easy way.
sir as i want to remove all the numeric digits i.e.
70,000.00
14,700.00
3,000.00
from the above series and want to keep only these values-
12-08-16
12-08-16
12-08-16
12-08-16
DL10587
DL10575
DL11318
DL2514
DL8526
DL36521
DL7485
in the clipboard then what would be the codes?
Code: Select all
F2::
Clipboard := Trim(RegExReplace(Clipboard, "m)^(\d\d-\d\d-\d\d)$|^(D[^\d]?\d+)$|^.*$", "$1$2"), " `r`n`t")
MsgBox % clipboard
Return
Sabestian Caine wrote:one more thing i would like to ask is that if i want remove only the numeric digit which starts from 7 as in the above series 70,000.00 starts from 7. i want that all the values except 70,000.00 should remain in the clipboard then what the codes should i use.
Code: Select all
F2::
Clipboard := Trim(RegExReplace(Clipboard, "m)^(\d\d-\d\d-\d\d)$|^(D[^\d]?\d+)$|^([^7].*)$|^7.*$", "$1$2$3"), " `r`n`t")
MsgBox % clipboard
Return
However, I forgot to explain the significance of the parenthesis. In all of the code I have provided here, the parenthesis both define a group of items and tell AutoHotkey to assign whatever that group matches to a placeholder variable. The first set of parenthesis is assigned to $1, the second set to $2, the third set to $3, and so on. Any group that does not have a match will result in a placeholder variable that contains nothing.
^.*$ matches an entire line, and does not assign it to a placeholder variable (because there are no parenthesis).
"$1$2" is the replacement string, and tells AutoHotkey to replace any matches with whatever was in the first & second sets of parenthesis.
^([^7].*)$ matches any line that does not start with a 7. This is because the [ ] brackets indicate a set of allowed options. Making ^ the first character inside the brackets changes it to disallow. This means [123] will match either 1, 2, or 3, and [^123] means it can not match.
- Sabestian Caine
- Posts: 528
- Joined: 12 Apr 2015, 03:53
Re: How to remove specific values from clipboard?
THANKS DEAR Shadowpheonix FOR MAKING ME UNDERSTAND ALL THESE THINGS SO BEAUTIFULLY...Shadowpheonix wrote:Sabestian Caine wrote:Thanks dear shadowpheonix for making me understand all these things in so easy way.
sir as i want to remove all the numeric digits i.e.
70,000.00
14,700.00
3,000.00
from the above series and want to keep only these values-
12-08-16
12-08-16
12-08-16
12-08-16
DL10587
DL10575
DL11318
DL2514
DL8526
DL36521
DL7485
in the clipboard then what would be the codes?Code: Select all
F2:: Clipboard := Trim(RegExReplace(Clipboard, "m)^(\d\d-\d\d-\d\d)$|^(D[^\d]?\d+)$|^.*$", "$1$2"), " `r`n`t") MsgBox % clipboard Return
Sabestian Caine wrote:one more thing i would like to ask is that if i want remove only the numeric digit which starts from 7 as in the above series 70,000.00 starts from 7. i want that all the values except 70,000.00 should remain in the clipboard then what the codes should i use.In both of these, the m)^(\d\d-\d\d-\d\d)$|^(D[^\d]?\d*)$ portion is the same as it was in the original code I provided you.Code: Select all
F2:: Clipboard := Trim(RegExReplace(Clipboard, "m)^(\d\d-\d\d-\d\d)$|^(D[^\d]?\d+)$|^([^7].*)$|^7.*$", "$1$2$3"), " `r`n`t") MsgBox % clipboard Return
However, I forgot to explain the significance of the parenthesis. In all of the code I have provided here, the parenthesis both define a group of items and tell AutoHotkey to assign whatever that group matches to a placeholder variable. The first set of parenthesis is assigned to $1, the second set to $2, the third set to $3, and so on. Any group that does not have a match will result in a placeholder variable that contains nothing.
^.*$ matches an entire line, and does not assign it to a placeholder variable (because there are no parenthesis).
"$1$2" is the replacement string, and tells AutoHotkey to replace any matches with whatever was in the first & second sets of parenthesis.
^([^7].*)$ matches any line that does not start with a 7. This is because the [ ] brackets indicate a set of allowed options. Making ^ the first character inside the brackets changes it to disallow. This means [123] will match either 1, 2, or 3, and [^123] means it can not match.
NOW ALMOST ALL THE THINGS ARE CLEAR IN MY MIND.....
I AM REALLY THANKFUL AND OBLIGED TO YOU AND YOUR SKILLS....
THANKS A LOT SIR....
I don't normally code as I don't code normally.
- Sabestian Caine
- Posts: 528
- Joined: 12 Apr 2015, 03:53
Re: How to remove specific values from clipboard?
Shadowpheonix wrote:Sabestian Caine wrote:Thanks dear shadowpheonix for making me understand all these things in so easy way.
sir as i want to remove all the numeric digits i.e.
70,000.00
14,700.00
3,000.00
from the above series and want to keep only these values-
12-08-16
12-08-16
12-08-16
12-08-16
DL10587
DL10575
DL11318
DL2514
DL8526
DL36521
DL7485
in the clipboard then what would be the codes?Code: Select all
F2:: Clipboard := Trim(RegExReplace(Clipboard, "m)^(\d\d-\d\d-\d\d)$|^(D[^\d]?\d+)$|^.*$", "$1$2"), " `r`n`t") MsgBox % clipboard Return
Sabestian Caine wrote:one more thing i would like to ask is that if i want remove only the numeric digit which starts from 7 as in the above series 70,000.00 starts from 7. i want that all the values except 70,000.00 should remain in the clipboard then what the codes should i use.In both of these, the m)^(\d\d-\d\d-\d\d)$|^(D[^\d]?\d*)$ portion is the same as it was in the original code I provided you.Code: Select all
F2:: Clipboard := Trim(RegExReplace(Clipboard, "m)^(\d\d-\d\d-\d\d)$|^(D[^\d]?\d+)$|^([^7].*)$|^7.*$", "$1$2$3"), " `r`n`t") MsgBox % clipboard Return
However, I forgot to explain the significance of the parenthesis. In all of the code I have provided here, the parenthesis both define a group of items and tell AutoHotkey to assign whatever that group matches to a placeholder variable. The first set of parenthesis is assigned to $1, the second set to $2, the third set to $3, and so on. Any group that does not have a match will result in a placeholder variable that contains nothing.
^.*$ matches an entire line, and does not assign it to a placeholder variable (because there are no parenthesis).
"$1$2" is the replacement string, and tells AutoHotkey to replace any matches with whatever was in the first & second sets of parenthesis.
^([^7].*)$ matches any line that does not start with a 7. This is because the [ ] brackets indicate a set of allowed options. Making ^ the first character inside the brackets changes it to disallow. This means [123] will match either 1, 2, or 3, and [^123] means it can not match.
dear shadowpheonix... i am back with one more little issue...
sir, i have a 14 digit number say 07721000012345 or 07721000005007 or 07721000000009 or 07721000000013 or 07721000000410
in the above numbers you may notice that the right sided digits- 12345, 5007, 9, 13, 410 are increasing or decreasing. on the other hand the left sided digits 077210000 are same or constant in all the numeric numbers. you may also notice that all the above five numeric numbers are containing 14 digits and zeros are increasing or decreasing to complete a number as in 07721000012345 there are 4 zeros before 1 and in 07721000005007 there is five zeros before 5. and so on. So i want that all the zeros and other digits should be removed and there should remain only right sided digits. for example if clipboard is containing 07721000012345 and i press f1 key then it should show 12345 in msgbox and if clipboard is containing 07721000000410 and i press f1 key then it should show 410 in msgbox. here is a fictitious example of codes-
Code: Select all
f1::
Clipboard:=07721000000410
Clipboard := Trim(RegExReplace(Clipboard, what would be the codes here))
msgbox % Clipboard
return
Thank you dear Shadowpheonix...
I don't normally code as I don't code normally.
-
- Posts: 1259
- Joined: 16 Apr 2015, 09:41
Re: How to remove specific values from clipboard?
Code: Select all
f1::
Clipboard:=07721000000410
Clipboard := LTrim(Trim(RegExReplace(Clipboard, ".*(\d{5})$", "$1")), "0")
msgbox % Clipboard
return
.* matches an unknown number of characters.
The parenthesis define a group (as I explained previously).
\d matches a numeric digit, and {5} means "repeat 5 times", so \d{5} means match 5 digits.
- AlphaBravo
- Posts: 586
- Joined: 29 Sep 2013, 22:59
Re: How to remove specific values from clipboard?
Code: Select all
str = 07721000012345 or 07721000005007 or 07721000000009 or 07721000000013 or 07721000000410
MsgBox % RegExReplace(str, "\b077210+") "`nor`n" ; use the constant part "07721" for matching
. RegExReplace(str, "\b0*\d*?0+") ; more dynamic
-
- Posts: 1259
- Joined: 16 Apr 2015, 09:41
Re: How to remove specific values from clipboard?
I had never thought of matching patterns that way. I like it.AlphaBravo wrote:Code: Select all
str = 07721000012345 or 07721000005007 or 07721000000009 or 07721000000013 or 07721000000410 MsgBox % RegExReplace(str, "\b077210+") "`nor`n" ; use the constant part "07721" for matching . RegExReplace(str, "\b0*\d*?0+") ; more dynamic
- Sabestian Caine
- Posts: 528
- Joined: 12 Apr 2015, 03:53
Re: How to remove specific values from clipboard?
Thanks dear AlphaBravo for providing me more dynamic codes.AlphaBravo wrote:Code: Select all
str = 07721000012345 or 07721000005007 or 07721000000009 or 07721000000013 or 07721000000410 MsgBox % RegExReplace(str, "\b077210+") "`nor`n" ; use the constant part "07721" for matching . RegExReplace(str, "\b0*\d*?0+") ; more dynamic
Thanks you very much sir...
I created these codes on my own with my little knowledge of ahk which are also working similar to your codes-
Code: Select all
f1::
clipboard:=07721000000410
var1:=SubStr(clipboard, 7, 10)
var2:= LTrim(var1,"0")
msgbox %var2%
I don't normally code as I don't code normally.
- Sabestian Caine
- Posts: 528
- Joined: 12 Apr 2015, 03:53
Re: How to remove specific values from clipboard?
Thanks dear Shadowpheonix....Shadowpheonix wrote:The LTrim is used to remove the leading 0s.Code: Select all
f1:: Clipboard:=07721000000410 Clipboard := LTrim(Trim(RegExReplace(Clipboard, ".*(\d{5})$", "$1")), "0") msgbox % Clipboard return
.* matches an unknown number of characters.
The parenthesis define a group (as I explained previously).
\d matches a numeric digit, and {5} means "repeat 5 times", so \d{5} means match 5 digits.
I created these codes on my own with my little knowledge of ahk which are also working fine-
Code: Select all
f1::
clipboard:=07721000000410
var1:=SubStr(clipboard, 7, 10)
var2:= LTrim(var1,"0")
msgbox %var2%
I don't normally code as I don't code normally.