getting the "title" between the names - postgresql

The name I'm working on is formatted like this:
King, Mr. Jay Thomas
Smith, Miss. Jane
How do I get the middle title part only using Postgres?
I'm a noob so this is definitely wrong:
SELECT position('%#," #"%#' for '#') AS TITLE
FROM titanic;`

You could use SUBSTRING with the regex pattern \w+\.:
SELECT SUBSTRING(title from '\w+\.')
FROM titanic;

Related

How do I convert a string to sentence case in Postgres

With the caveat that this is not a silver bullet, I submit this question and provide my own answer, since after a reasonable college effort, I found myself with no solutions for PostgreSQL.
The task in my case is to convert a collection of largely upper-case-only sentences into a reasonable facsimile of a paragraph using capitalization for just the first letter of each sentence. If that solution is out there, either I'm blind or it was decently well hidden.
So, for example, how do I convert
THE NAME IS BOND. JAMES BOND. 007. AND THIS IS ONE COOL PIECE OF CODE.
to
The name is bond. James bond. 007. And this is one cool piece of code.
?
Here is what I came up with. I'd be glad to award the answer to a better solution!
WITH fixed_sentences_source AS (
WITH single_sentences_source AS (
WITH arrays_source AS (
SELECT
regexp_split_to_array(LOWER('THE NAME IS BOND. JAMES BOND. 007. AND THIS IS ONE COOL PIECE OF CODE.'), '\. ' ) AS arrays
)
SELECT TRIM(UNNEST(arrays)) AS single_sentences
FROM arrays_source
)
SELECT
UPPER(SUBSTRING(single_sentences, 1, 1)) || SUBSTRING(single_sentences, 2, LENGTH(single_sentences) - 1) AS fixed_sentence
FROM single_sentences_source
WHERE
single_sentences <> ''
)
SELECT ARRAY_TO_STRING(ARRAY(SELECT fixed_sentence FROM fixed_sentences_source), '. ')

How to rename files with only 1 occurrence? [duplicate]

I am having some issues with regular expression mainly because I think the information I can find is not specifically for powershell and all the samples I have tried either error or don't work as intended. I am trying to replace the first occurrence of a word in a string with another word but not replace any other occurrences of that word. for an example take the string:
My name is Bob, her name is Sara.
I would like to replace the first occurrence of name with baby so the resulting string would be
My baby is Bob, her name is Sara.
I have been working in https://regex101.com/ to try to build and see what is selected as I go but as I said none of these have a powershell flavor of regex. In that I can just turn off the global flag and it seems to select the first occurrence but not in powershell. So I am really at a loss of where to begin all really have at this point is selecting all occurrences of the word namewith:
$test = "My name is Bob, her name is Sara."
$test -replace 'name', 'baby'
One way to replace n times:
$test = "My name is Bob, her name is Sara."
[regex]$pattern = "name"
$pattern.replace($test, "baby", 1)
> My baby is Bob, her name is Sara
You could capture everything before and behind and replace it:
'My name is Bob, her name is Sara.' -replace '(.*?)name(.*)', '$1baby$2'

postgresql remove characters start with

I want to make a postgresql query which removing characters. For example, my datas are like this;
John Smith https://john.smith.com
Allen Paul https://allen.paul.com
I want to remove characters which start with https. I want to see in the final like this;
John Smith
Allen Paul
Can anybody help me. Thanks...
split_part is good for this:
t=# select split_part('Allen Paul https://allen.paul.com',' https://',1);
split_part
------------
Allen Paul
(1 row)
Time: 1.370 ms

Replacing only the first occurrence of a word in a string

I am having some issues with regular expression mainly because I think the information I can find is not specifically for powershell and all the samples I have tried either error or don't work as intended. I am trying to replace the first occurrence of a word in a string with another word but not replace any other occurrences of that word. for an example take the string:
My name is Bob, her name is Sara.
I would like to replace the first occurrence of name with baby so the resulting string would be
My baby is Bob, her name is Sara.
I have been working in https://regex101.com/ to try to build and see what is selected as I go but as I said none of these have a powershell flavor of regex. In that I can just turn off the global flag and it seems to select the first occurrence but not in powershell. So I am really at a loss of where to begin all really have at this point is selecting all occurrences of the word namewith:
$test = "My name is Bob, her name is Sara."
$test -replace 'name', 'baby'
One way to replace n times:
$test = "My name is Bob, her name is Sara."
[regex]$pattern = "name"
$pattern.replace($test, "baby", 1)
> My baby is Bob, her name is Sara
You could capture everything before and behind and replace it:
'My name is Bob, her name is Sara.' -replace '(.*?)name(.*)', '$1baby$2'

Title the Result from SphinxSearch

Any way I can title the search results?
Example:
select name from person ;
Will give
abhilash joseph c
But i want it to be 'Abhilash Joseph C'
Can I write udf for sphinx? How can I do it ?