value.replace(/([^|])\|([^|])/,"$1~$2")Thanks Owen
Unfortunately one of the problems is that the pattern can be more varied (e.g. a value could end with 1-5 pipes).
I haven’t tested it yet, but I think my plan is to do something like this:
Best wishes
Graham
--
You received this message because you are subscribed to the Google Groups "OpenRefine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
openrefine+...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/openrefine/66d5467e-0d18-4a44-be60-cb5ce431004b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
forEachIndex(value.smartSplit("|"),i,v,if(mod(i,5)==4,v+"~",v)).join("|")
To unsubscribe from this group and stop receiving emails from it, send an email to openr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openrefine/66d5467e-0d18-4a44-be60-cb5ce431004b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks Owen!
Yes, that is definitely simpler and seems to work perfectly. In fact, it pretty much does exactly what I was hoping to achieve.
I just added .replace(“~|”,”|~”) to the end of the expression so that the ~ separator follows the 5th pipemark.
Thanks again!
To unsubscribe from this group and stop receiving emails from it, send an email to
openrefine+...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/openrefine/2fed0f00-57bb-469a-8ff6-0bef5b8d4c3b%40googlegroups.com.
value.replace(/((?:[^|]*\|){5})/,"$1~")
Thanks Owen
That also works perfectly. I’m sure a similar problem will crop up again. So hopefully the logic behind these will come in handy on future occasions as well.
To unsubscribe from this group and stop receiving emails from it, send an email to
openrefine+...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/openrefine/e0154273-1593-4569-a239-868d834a90c3%40googlegroups.com.
def nth_repl(s, sub, repl, nth):
find = s.find(sub)
# if find is not p1 we have found at least one match for the substring i = 1
# loop util we find the nth or we find no match while find != -1 and i != nth: # find + 1 means we start at the last match start index + 1 find = s.find(sub, find + 1) i += 1 # if i is equal to nth we found nth matches so replace
if i == nth: s= s[:find]+repl+s[find+1:] return s[:find] + nth_repl(s[find:], sub, repl, nth) else: return s
return nth_repl(value, "|", "\n", 5)Owen
The information contained in this e-mail is confidential and may be legally privileged. It is intended for the addressee(s) only. If you are not the intended recipient, please delete this e-mail and notify the post...@bl.uk : The contents of this e-mail must not be disclosed or copied without the sender's consent.
The statements and opinions expressed in this message are those of the author and do not necessarily reflect those of the British Library. The British Library does not take any responsibility for the views of the author.
*****************************************************************************************************************
Think before you print
--
You received this message because you are subscribed to the Google Groups "OpenRefine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openrefine/2fed0f00-57bb-469a-8ff6-0bef5b8d4c3b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "OpenRefine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openr...@googlegroups.com.
Thanks Ettore
I recently started an online python tutorial and I’ve probably done about a 12 hours, so I’ll see If I’ve learnt enough to adapt this.
To unsubscribe from this group and stop receiving emails from it, send an email to
openrefine+...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/openrefine/f9ea1a90-4628-4d22-8168-74a0f6dfb894%40googlegroups.com.
\numberMatches the contents of the group of the same number. Groups are numbered starting from 1. For example, (.+) \1 matches 'the the' or '55 55', but not 'thethe' (note the space after the group). This special sequence can only be used to match one of the first 99 groups. If the first digit of number is 0, or number is 3 octal digits long, it will not be interpreted as a group match, but as the character with octal value number. Inside the '[' and ']' of a character class, all numeric escapes are treated as characters.