This is not very helpful.
Would you care to elaborate? In what way does it not work? Wrong output? if yes, which? Or does it raise an error? if so, which? | [reply] |
The scanner gives me the original scanned barcode without changing anything. But no errors at all.
Is your solution
s/\b(\d+)\b/reverse sprintf "%013d", scalar reverse $1/eg;
a real regex? or has it already some extra program-lines? (like sprintf...)
| [reply] |
It's a substitution, which contains a regex.
As you've been told multiple times in the chatterbox, a regex can't change a string, it just either matches or it does not. So your project to modify a string with a regex is pretty much doomed.
I suspect that it's either not possible in your setup, or you missed some small but important detail in the documentation.
| [reply] |
Here a extract of the manual:
How do I specify arbitrary text substitution?
Enter text in the Regular expression: text box. The syntax for the string is:
/search/replace/g
where search is the string to search for and replace is the string to replace search with. By default, only the first occurrence of search is replaced. To replace all instances, add g at the end of the command.
For example, if the reader decodes this string:
UPC 05214275600
You could replace the string "UPC" with the string "SKU CODE:" by using this substitution string:
/UPC/SKU CODE:/
which would produce this output string:
SKU CODE: 05214275600
You can enter multiple susbstitution pairs separated by a space. Multiple pairs are used sequentially: the result of the first pair is used as input for the second pair, and so on.
AND ALSO:
How do I use a wildcard to match different characters or patterns?
You can match any single character, any character from a set of characters, any character from a range of characters, or any character that is not within a range of characters using these special characters in the search string:
. Match any single character
abcd... Match any single character from the set a, b, c, d ...
a-z Match any single character within the range of characters a through z (letters or numbers can be used)
To invert the sense of a wildcard using a set or range of characters, precede the characters with a ^ character.
To match a variable number of characters, append one of the following modifier characters to the character or wildcard being matched:.
+ matches one or more of the preceding character
* matches zero or more of the preceding character
? matches zero or one of the preceding character
{n} matches n instances of the preceding character
{n,m} matches at least n but not more than m instances of the preceding character
{n,} matches at least n instances of the preceding character
Here are some examples of wildcard matching:
/A.B/AB/g removes any single character between 'A' and 'B' in the input string
/A.*B/AB/g removes any number of characters from between 'A' and 'B' in the input string
| [reply] |
Obviously you have to remove the leading s of s/... then. If that still does not work, you can use a really ugly hack by making a regex for each possible string length:
/\b(\d)/${1}000000000000/
/\b(\d{2})/${1}00000000000/
/\b(\d{3})/${1}0000000000/
/\b(\d{4})/${1}000000000/
/\b(\d{5})/${1}00000000/
...
That still assumes that the RHS is actually interpolated by your misterious program. If it's not, you could still try to work with look-behinds:
/(?<=\b\d)$/000000000000/
/(?<=\b\d{2})$/00000000000/
/(?<=\b\d{3})$/0000000000/
/(?<=\b\d{4})$/000000000/
/(?<=\b\d{5})$/00000000/
/(?<=\b\d{6})$/0000000/
...
(not tested) | [reply] [d/l] [select] |
s/$/
+ /; s/^\(.\{1,100\}\).*/\1/;
The first substitution has 100 or more spaces on the rhs.
| [reply] [d/l] |
s/(\d+)/sprintf("%013d", $1)/eg
Update: that's what I get for not reading the OP carefully...
how about (and being slow...oh well):s/(\d+)/reverse(sprintf("%013d", scalar(reverse($1))))/eg;
| [reply] [d/l] [select] |