am trying the following regex_replace statement in PostgreSQL (9.2)
# SELECT regexp_replace('_this._is_a_long_entry._of.nonsense_text', '\._|^_', '$','g');
Objective:
is to replace all underscore characters preceded by a period with '$'. Am also replacing the underscore anchored at position 1; this is working. I'd like to cram both matches into the one statement. All of this is to develop a mechanism for pushing some weird text we have into a PostreSQL ltree structure.
Issue:
How to make the first replacement above work, without molesting the period character?
I'd like to see the result look like this:
$this.$is_a_long_entry.$of.nonsense_text
Note: Have also tried explicit capture of the underscore, but the PG implementation seems to ignore this:
# SELECT regexp_replace('_this.is_long_entry._of.nonsense_text', '\.(_)|^_', '$','g');
?then but alternation (|) does generally work in subpatterns in regex. how about\.(_)|^(_)?