Copy link to clipboard
Copied
Hello!
I would like to cover up various eventualities in the search GREP with. What is wrong in my mindset?
Find: (\\t+)([\\s|\\t|][ab]€[\\s|\\t|]\\d{1,3},\\d{2}$)
Change: ~y$2
It should look for one or more tabs before a price. After that tyb could be: nothing, a space or another tab; after that could be the word "ab" or nothing; after that "€"; after that nothing, a space or a tab. Is that not the correct notation?
Ok, I see. You can make your search pattern more general:
Find: \s+(?=(ab\s?)?€.+$)
Replace with ~y
Note: in (\t*\s*) again, \s matches any space, including the tab, so you can leave out \t. In addition, \s* searches for any space, including none, so it matches anything. So (\t*\s*) looks for zero or more tabs followed by zero or more spaces. And finally, there's no need for the parentheses because you don't refer back to them and you don't group them. I think you confuse brackets and parentheses:
...Copy link to clipboard
Copied
Are you wrapping this is quotes?
Also, [ab] will find a and b separately.
Copy link to clipboard
Copied
If after the tab could be nothing then use \\s?\\t? this allows there to be no spaces or tabs. You wouldn't need a character class for this so just do:
Copy link to clipboard
Copied
What does [[.ab.]] mean?
Copy link to clipboard
Copied
Show us a screenshot (with visible metachars]? Thanks!
(^/)
Copy link to clipboard
Copied
Sometimes there are prices without the word "ab", or somebody placed a tab instead a space...
Copy link to clipboard
Copied
Hi jakec42735283
Yes I did. The posting contains just the pure GREP.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hello,
There's few mistakes:
(\\t+)([\\s|\\t|][ab]€[\\s|\\t|]\\d{1,3},\\d{2}$)
"|" means "OR", but ending with "|]" doesn't mean "OR nothing".
You can use "?" that means "find one or zero"
(\\t+)([\\s|\\t|][ab]€[\\s|\\t|]\\d{1,3},\\d{2}$)
You allready searched for leading tabs, and there's no need for parenthesis since you'll only use the second part.
I did some tests with Firefox, inDesign javascript and GREP :
//inDesign and Firefox don't understand "[[.ab.]]" (but "[[.xxx.]]" is documented in other programs)
alert(/\t+(\s?[[.ab.]]?€[\s|\t]?\d{1,3},\d{2})$/.test(" ab€ 123,25")); // false (browser, inDesign javascript & GREP)
alert(/\t+(\s?ab€[\s|\t]?\d{1,3},\d{2})$/.test(" ab€ 123,25")); // ok
alert(/\t+(\s?ab€|\s?€)([\s|\t]?\d{1,3},\d{2})$/.test(" ab€ 123,25")); // ok (ID javascript & GREP)
alert(/\t+(\s?ab€|\s?€)([\s|\t]?\d{1,3},\d{2})$/.test(" € 123,25")); // ok (ID javascript & GREP)
alert(" € 123,25".replace(/\t+(\s?ab€|\s?€)([\s|\t]?\d{1,3},\d{2})$/, "'$1$2'")); // ok " € 123,25"
Unless you use inDesign findGrep(), there's no need for double slashes.
You need:
\t+ // for leading tabs
(\s?ab€|\s?€) // for space or not and "ab" or not and € (you'll always have a $1)
([\s|\t]?\d{1,3},\d{2}) // tab or space and price
$ // this is the end...
// complete expression:
\t+(\s?ab€|\s?€)([\s|\t]?\d{1,3},\d{2})$
// to be replaced by:
$1$2
//if you use findGrep:
\\t+(\\s?ab€|\\s?€)([\\s|\\t]?\\d{1,3},\\d{2})$
I hope this help,
Swo
Copy link to clipboard
Copied
Thank you.
But I do not think I´ll get problems with the browser. There are no interfereces.
Copy link to clipboard
Copied
Don't use | in character classes. [\s|\t] is wrong. Not only because of the |, but also because \s covers \t. So instead of [\s|\t] use simply \s
This grep seems to match what you want.
\t+(ab\s)?€\s?
Peter
Copy link to clipboard
Copied
Hi Peter.
This is how the (experimental-)lines look before the change...:
... and these are the same lines after using youre script-snippet (\t+(ab\s)?€\s?):
As you can see, Not every row was addressed.
I use now a longer version like this:
So far, it works flawlessly. Let´s see how long...
Copy link to clipboard
Copied
Hi,
Didn't you loose some "€" in this ?
(?=) doesnt accept complex expression, as "*+", but simpler ones as (?=ab), (?=\d)
I would use find :
\t\s?([a-z ]+€|€)\s+
replace by:
~y$1
Beginning with "\t" won't get " \tblau" (space + tab + "blau")
[a-z ]+ will get "rot " or "ab " or "rot ab "
an we need "\s+" to strip tab(s) after "€"
The replacement is "~y$1 " (with a space at the end)
Swo
Copy link to clipboard
Copied
Hey Swo.
You are right, there less €-s than before. I've completly overlooked.
What I want is, to change the tab AFTER that word (e.g. "blau"). However, there is not one word in front of the tab in each line. So I have to focus on what is after the tab.
Copy link to clipboard
Copied
Hum,
Did you give all possible line examples ?
If yes, I suppose there's always a " \tQUALITY" (space+tab+color) in each line
So we'll just have to ensure there's a "~y" after, instead of other spaces:
Find: "( \t[^\s]+)\s+" and replace with: "$1~y"
Second, we always need a space after € (and take the text before € if there's any):
Find: "([\u\l ]+€|€)\s+" and replace with: "$2 " (a space at the end)
The complete expression without ‘"’:
"( \t[[^\s]+)\s+([\u\l ]+€|€)\s+"
replacement:
"$1~y$2 "
Now, the misplaced "rot" is in its column.
When you can't do it in 1 search/replace, try to have the more regular text with a first search/replace, and finish with a second one, or more.
we don't mind if we can script them.
Swo.
Copy link to clipboard
Copied
Ok, I see. You can make your search pattern more general:
Find: \s+(?=(ab\s?)?€.+$)
Replace with ~y
Note: in (\t*\s*) again, \s matches any space, including the tab, so you can leave out \t. In addition, \s* searches for any space, including none, so it matches anything. So (\t*\s*) looks for zero or more tabs followed by zero or more spaces. And finally, there's no need for the parentheses because you don't refer back to them and you don't group them. I think you confuse brackets and parentheses: (\s\t) stands for 'a space followed by a tab'; [\s\t] stands for 'a space or a tab'.
Peter
Copy link to clipboard
Copied
That´s pretty cool! Short and effective. "Reduced to the max" (a slogan for the Smart)