Generally you can use regexp_replace()
or substring()
with regular expressions to cut most anything from your strings, as long as you can define it clearly.
In your case, something like:
SELECT regexp_replace(string, 'http:[^[:space:]]+(:?\s*#p\d+)?', '') AS trimmed
Or simpler, according to your later comment:
the part of string beginning with http until the next space
(or end of string, I may add)
SELECT regexp_replace(string, 'http:[^[:space:]]+', '') AS trimmed
Replaces the first occurrence of the pattern. Add the global switch 'g'
, if there can be more.
Explain
[^[:space:]]
.. character class of all non-whitespace character.
^
.. negates the class.
[:space:]
.. character class for white space characters as defined by your locale.
Cuts any part starting with http:
up to the next white space character. Plus, optionally, a dangling #p
followed by a number.
+
.. one or more atoms
More explanation under this recent, related question:
Regex failing to match number and dash with letter (or space and letter)