How to take substring - postgresql

I have a list, and I need to take only first words including numbers of every row without anything after numbers. How can I achieve that?
A pic is provided
For example:
I have a row like this:
ЛУ 344 ул.Яссауй в районе дома №163 северном направление
As a result I want to get:
ЛУ 344
Left, right won't help because the number of characters can change.

You can use a regex based substring() variant:
substring(the_column from '\w+\s+[0-9]+')
This will extract the first "word characters" followed by one or more spaces followed by one or more numbers
Online example

Maybe split_part() will help.
Or the string_to_array()
Or the substring()
Depends on the use you want and the way you want to get the substring.

Related

selecting cases based upon first few characters in spss?

i want to select cases with particular first 3 characters.
for example cases with first 3 characters containing "I22".
the length of whole value can vary. e,g "I228" or "I2279" but they have common first three characters "I22"
i usually use compute variable_name= "I228".
but this is tedious as i have to enter all variation of "I22" e.g "I228", "I229" and so on..
it would be much easier if i can just select cases based upon same first 3 characters
you can use the char.cubstr function to find out what the first three characters are in your string variable. For example:
if char.substr(variable_name,1,3)="I22" keep_this=1.
or:
select cases if char.substr(variable_name,1,3)="I22".

How do I remove the first or last n characters from a value in q/ kdbstudio?

I've looked into the underscore for drop/cut, but this only seems to remove the first or last n entries, not characters. Any ideas?
Depends on what you're using drop cut on.
Can you provide an example of your values?
Below shows how cut can be used on a sting and then a list of strings.
It uses each right to drop a value from each item.
http://code.kx.com/q/ref/adverbs/#each-right
q)1_"12456789"
"2456789"
q)
q)1_("12456789";"12456789")
"12456789"
q)
q)1_/:("12456789";"12456789")
"2456789"
"2456789"
#Connor Gervin had almost what I wanted, but if you want to cast back to a string, you can use `$(-3)_'string sym from tab

emacs orgmode table use the equal sign without starting a formula

I'm typing up a table with org mode, where the equal sign(=) if the first character in the cell and it want to start a formula. how do I get it to display the symbol without it being a formula, of a way to use formulas to display it. I get errors when I use single quotes, and I see the Unicode decimal value when using double quotes.
I have tried the following
='=+'
="=+"
they give
#ERROR
[61, 43]
Use an escaped entity, \equal{} and it should display as you wish. See the variable org-entities for others you can use.
I'm a bit late :D
There may be a better way, but you can try with :='(format "=+")
Source: https://emacs.stackexchange.com/questions/19183/can-i-use-formula-to-manipulate-text-in-org-mode-table
When I ran into this problem just now, I found that I was able to get around it by replacing the equals sign with some other similar-looking character. Two which come to mind are ꞊ ‘U+A78A MODIFIER LETTER SHORT EQUALS SIGN’ and ⹀ ‘U+2E40 DOUBLE HYPHEN’.

Regular Expression for number.(space), objective-c

I have an NSArray of lines (objective-c iphone), and I'm trying to find the line which starts with a number, followed by a dot and a space, but can have any number of spaces (including none) before it, and have any text following it eg:
1. random text
2. text random
3.
what regular expression would I use to get this? (I'm trying to learn it, and I needed the above expression anyway, so I thought I'd use it as an example)
With C#:
#"^ *[0-9]+\. "
It doesn't check for the presence of something after the ., so this is legal:
1.(space)
If you delete the # and escape the \ it should work with other languages (it is pretty "down-to-earth" as RegExpes go)
I may suggest (Perl-compatible regexp):
^\s*\d+\.\s
At the beginning of a line:
Any number (0-n) of spaces
One or more digits
A dot
A space
Something like
^\s*\d+\.
But it depends on the language.
/^\s*[0-9]+\.\s+/
would be my guess providing you don't have any space before the number

crystal reports : substring error

I've developed a workaround since crystal reports doesn't seem to have a substring function with the following formula:
right({_v_hardware.groupname},
truncate(instr(replace({_v_hardware.groupname},".",
","), ","))
What I'm trying to do is search for the period (".") in a string and replace it with a comma. Then find the comma position in the string and print all characters following after the comma. This is assuming the string will only have 1 period in the entire string.
Now when I attempt to do this, I get some weird characters which look like wingdings. Any ideas?
thanks in advance.
I don't know the entire issue that you are attempting to accomplish, but for this question alone, the step of replacing the period with a comma seems to be unnecessary. If you know that there is only one period in the string and you only want the characters right of the period then you should be able to do something like the following (this is #first_formula):
right({_v_hardware.groupname}, len({_v_hardware.groupname}) - instr({_v_hardware.groupname},"."))
If for some reason you want to show the comma then I'd do that in a separate formula. If you need the entire screen with the comma replaced then just do:
replace({_v_hardware.groupname},".",",")
And if you need the comma plus included in the string then it might just be easier to do something like:
"," + {#first_formula}
Hope this helps.