I want to split my filename (14-07-2022-Pencil-200 (Zane)) using vb.net
Date: 14-07-2022
Product : Pencil
Quantity : 200
Buyer : Zane
Result :
TextBox 1 : 14-7-2022
TextBox 2 : Pencil
TextBox 3 : 200
TextBox 4 : Zane
You can use Left(), instr() or substring() functions.
I can give you logic - i don't know which are exact function names in vb.net.
Logic is:
Use left(filename,10) go get date. (here : 14-07-2022)
Use substr() or relative function starting from character 11 to last occurrence of "-". this will give you Product Name (here : Pencil)
again user substring starting from last occurrence of "-" to first occurrence of character space (" "). (here : 200)
Use again substring starting from first occurrence of character "(" to end of file name string. (here : Zane)
Related
I want to mask movie names with XXXXXXXX in a PostgreSQL table column. The content of the column is something like
hollywood_genre_movieTitle0=The watergate&categorey=blabla&hollywood_genre_movieTitle1=Terminator&hollywood_genre_movieTitle2=Spartacus&hollywood_genre_movieTitle3=John Wayne and the Indians&categorey=blabla&hollywood_genre_movieTitle4=Start Trek&hollywood_genre_movieTitle5=ET&categorey=blabla
And I would like to mask the titles (behind the pattern hollywood_genre_movieTitle\d) using the regexp_replace function
regexp_replace('(hollywood_genre_movieTitle\d+=)(.*?)(&?)', '\1XXXXXXXX\3', 'g')
This just replaces the first occurrence of a title and and cuts the string. In short this expression does not do the thing I want. What I would like is that all movies names are replace with XXXXXXXX.
Can someone help me solve that?
The regex does not work because (.*?)(&?) matches an empty string or & lands in Group 3 if it immediately follows hollywood_genre_movieTitle\d+= pattern.
You need to use a negated character class [^&] and a + quantifier to match any 1 or more chars other than & after the hollywood_genre_movieTitle\d+= pattern.
SELECT regexp_replace(
'hollywood_genre_movieTitle0=The watergate&categorey=blabla&hollywood_genre_movieTitle1=Terminator&hollywood_genre_movieTitle2=Spartacus&hollywood_genre_movieTitle3=John Wayne and the Indians&categorey=blabla&hollywood_genre_movieTitle4=Start Trek&hollywood_genre_movieTitle5=ET&categorey=blabla',
'(hollywood_genre_movieTitle\d+=)[^&]+',
'\1XXXXXXXX',
'g')
See the online demo.
Details
(hollywood_genre_movieTitle\d+=) - Capturing group 1:
hollywood_genre_movieTitle - a substring
\d+= - 1 or more digits and a = after them
[^&]+ - 1 or more chars other than &.
I have found a ton of ways to transpose columns to text in Notepad++ and vice versa. However, where I'm struggling is that I have one column with several rows. I can't 'just' transpose these as the data winds up being in the wrong order.
Example:
RANK
COMPANY
GROWTH
REVENUE
INDUSTRY
1
Skillz
50,058.92%
$54.2m
Software
2
EnviroSolar Power
36,065.06%
$37.4m
Energy
When I transpose this, I wind up with:
RANKCOMPANYGROWTHREVENUEINDUSTRY 1Skillz50,058.92%$54.2mSoftware2EnviroSolar Power36,065.06%$37.4mEnergy
I need everything to remain in groups so I wind up with the following, noting that I also need a delimiter added:
RANK|COMPANY|GROWTH|REVENUE|INDUSTRY
1|Skillz|50,058.92%|$54.2m|Software
2|EnviroSolar Power|36,065.06|$37.4m|Energy
As you can see with the company EnviroSolar Power, there is a space between "EnviroSolar" and "Power" and anything I've tried winds up removing the spaces that should remain in tact when transposing.
I appreciate ANY help you can offer! Thank you in advance!
Assuming that your rows always start with integers (except for the header row of course) and furthermore, that only the first column contains integers you could do do that with two search replace (Ctrl+H).
Be sure to opt for 'Regular expression' search mode.
First replace all newlines with pipes. This will put everything on one line for now.
Find what: \n
Replace with: |
Next find all pure numeric fields and make them start of a line to reach the desired result.
Find what: \|([0-9]+)\|
Replace with: \n$1|
If you know the number of columns, in fact here it is 5, you could do in two steps:
First:
Ctrl+H
Find what: (?:[^\r\n]+\R){5}
Replace with: $0\n
Replace all
Explanation:
(?: : start non capture group
[^\r\n]+ : 1 or more any character but line break
\R : any kind of line break
){5} : group must occurs 5 times,
here you can give the columns number of your choice
This will add a linebreak after 5 columns.
Check regular expression
Second:
Ctrl+H
Find what: (\R)(?!\R)|(\R\R)
Replace with: (?1|:\n)
Replace all
Explanation:
(\R) : any kind of line break, in group 1
(?!\R) : negative lookahead, make sure we have not another linebreak after
| : OR
(\R\R) : 2 line break, in group 2
Replacement:
(?1 : conditional replacement, is group 1 existing
| : yes ==> a pipe
:\n : no ==> linebreak
) : end condition
This will replace a single linebreak by a pipe and 2 consecutive linebreaks by a single one
Result for given example:
RANK|COMPANY|GROWTH|REVENUE|INDUSTRY
1|Skillz|50,058.92%|$54.2m|Software
2|EnviroSolar Power|36,065.06%|$37.4m|Energy
The regex I want to use is: ^(?=.*[,])(,?)ABC(,?)$
What I want to get out is:
^ // start
(?=.*[,]) // contains at least one comma (,)
(,?)ABC(,?) // The comma is either in the beginning or in the end of the string "ABC"
$ // end
Of course ABC is ought to be a variable based on my search term.
So if ABC = 'abc' then ",abc", "abc,", ",abc," will match but not "abc" or "abcd"
Better way to do this is also welcome.
The value in the record looks like "abc,def,ghi,ab,cde..." and I need to find out if it contains my element (i.e. 'abc'). I cannot change the data structure. We can assume that in no case the record will contain only one sub-value, so it is correct to assume that there always is a comma in the value.
If you want to know if a comma delimited string contains abc, then I think like is the easiest method in any database:
where ',' + col + ',' like '%,abc,%'
If I have table contents that looks like this :
id | value
------------
1 |CT 6510
2 |IR 52
3 |IRAB
4 |IR AB
5 |IR52
I need to get only those rows with contents starting with "IR" and then a number, (the spaces ignored). It means I should get the values :
2 |IR 52
5 |IR52
because it starts with "IR" and the next non space character is an integer. unlike IRAB, that also starts with "IR" but "A" is the next character. I've only been able to query all starting with IR. But other IR's are also appearing.
select * from public.record where value ilike 'ir%'
How do I do this? Thanks.
You can use the operator ~, which performs a regular expression matching.
e.g:
SELECT * from public.record where value ~ '^IR ?\d';
Add a asterisk to perform a case insensitive matching.
SELECT * from public.record where value ~* '^ir ?\d';
The symbols mean:
^: begin of the string
?: the character before (here a white space) is optional
\d: all digits, equivalent to [0-9]
See for more info: Regular Expression Match Operators
See also this question, very informative: difference-between-like-and-in-postgres
I have a text file that its structure is not in a single line, it is certain that the lines start with zero (0). Below is the sample:
header : TEXT<br>
header : TEXT<br>
header : TEXT<br>
line 1 : 0TEXT Name Other Field<br>
line 2 : TEXT Other Field Phone<br>
line 3 : 0TEXT Name Other Field<br>
line 4 : TEXT Other Field Phone<br>
line 5 : 0TEXT textexttexttext <br>
line 6 : 0TEXT Name Other Field<br>
line 7 : TEXT Other Field Phone<br>
line 8 : 0TEXT Name Other Field<br>
line 9 : TEXT Other Field Phone<br>
What I want to do is get through a regex evaluation the NAME and the PHONE fields and store this values.
Name, Phone
Name, Phone
The regex part is ok, I already did it.
What I need to know is how to get the values from two different lines and put it in the same register?
I found this forum http://forums.pentaho.com/showthread.php?53288-Reading-multi-line-records-from-text-file-newbie and tried to apply a javascript suggested, but it didn't work for me, maybe I did something wrong..
I really did some simple wrong and fixed it.
js..
var x;
var charInitial = line.toString().charAt(0);
if(charInitial == '0') {
x = line.toString();
}
else{
x += line.toString();
}
With this script I get the rows separated, I want to concatenate them and after apply the regex. I can concatenate all the rows that belong to the group, and with a regex I can drop that ones that are unnecessary.
Thanks
Given that you have those records in multiple rows, you have the following options:
1) Group by: as long as you can identify your rows that belong together via some set of keys, you can use a group by and create two new fields, Name and Phone, obtained by "Concatenate fields separated by" (not the "concatenate fields separated by ,", mind that). If the values are either what you want to keep or null, the concatenation works;
2) De-normalize. Same principle applies, you need a set of keys to identify records that belong together, but you will need both your Name and Phone to be in the same field (e.g, Value) and you need another field with the key (either Name or Phone).
3) Perhaps the best one: Analytic Query: Use "Lag N rows forward and get field" with N=1 and you get the phone number of the next row. After this step you have rows with a Not null name and the next row's phone number; rows with a null name and a null phone number. Filter the rows you want after and you're done.
This is just a generic idea. You have to sort out the details.