I currently have some rows that are not formatted properly. Essentially, I am storing chocolates in the following format XXXX CHOC00X. So, for example, in the list below Bounty CHOC001 is valid. But then any chocolates that don't follow this format are invalid. Please see list below:
Chocolates
Bounty CHOC001
twIX CHOC002
snickers CHOC003
Mars choc004
kinder Bueno ch0c005
dairymilk cHOc006
wisPa choC007
As you can see entries like twIX CHOC002 and kinder Bueno ch0c005 are invalid. I want something like this:
Chocolates
Bounty CHOC001
Twix CHOC002
Snickers CHOC003
Mars CHOC004
Kinder Bueno CHOC005
Dairymilk CHOC006
Wispa CHOC007
I tried using this formula PROPER() but then it only capitalises each word which is good by then CHOC001 would then instead be Choc001. Not sure if there is a way to apply the same conditional formatting of the first column.
Thanks
Try
={"Chocolates"; ArrayFormula(regexreplace(proper(A2:A8); "(?i)Ch(o|0)c"; "CHOC"))}
Change range to suit and see if that helps?
A more general solution
={"Chocolates ";
INDEX(IFERROR(PROPER(REGEXEXTRACT(F2:F,"(.+:?\w+ )"))&
"CHOC"®EXEXTRACT(F2:F,"(\d+$)")))}
"(.+:?\w+ )" get everything until before last space
"(\d+$)" get digits from end and add before them CHOC
Related
I have this string
location = '\\dev-something-again-n2\Staples\Started\477'
location = '\\dev-something-again-n2\Staples\Started\477\'
and i need to pull out the 477 out of it...any ideas of a good way to do this ...i was trying
location.partition("\")
but got nothing ....
location.split('\\').last
partition isn't the right tool here - it splits once on the string, rather than splitting on all the places it is found, as documented:
partition(sep) => [head, sep, tail] click to toggle source
Searches the string for sep and returns the part before it, the sep, and the part after it. If sep is not found, returns str and two empty strings. If no argument is given, Enumerable#partition is called.
split is the right tool for the job, if you want to do this by breaking the content apart.
Try using:
File.split(location).last
or
File.basename(location)
location.chomp('\\').match(/(?:.*\\)(.*)/)[1]
I need to match only strings that include one character / between numbers or integer numbers.
Examples:
1 YES
1/2 YES
some_text NO
some/test NO
some NO
2///2 NO
/12 NO
1/2/ NO
1.2/3 NO
Edit:
By rubular.com i`m tried to check this regex: /\d+(\/\d+)?
How regex should looks like?
If you're only including whole numbers or fractions:
\d+(\/\d+)?
If you also want to allow decimals:
\d+(\.\d+)?(\/\d+(\.\d+)?)?
Edit: Note that I'm making a lot of assumptions about what you really want. Bart Kiers's comments to your question are very important -- I took the liberty of assuming that what you want is numbers. If that isn't true, please clarify the question.
Edit2: I'm also making one more important assumption. Your question says "strings that include / or integer number." If you want to make sure that the string is ONLY a number and nothing else, then add ^ to the beginning of the line and $ to the end. Example:
^\d+(\/\d+)?$
Given this:
Come Find me please. This is paragraph one.\n\nThis is paragraph two.
Capture everything before me as this is the last sentence.\n\n\n\n
From: XXX XXX <xxxxx#gmail.com>\nDate: Mon, 17 May 2010 10:59:40 -0700\n
To: \"xxx, xxx\" <xxxxx#intuit.com>\nSubject: Re: XXXXXXXX\n\ndone
Lots of other junk here
What I want back is:
Come Find me please. This is paragraph one.\n\nThis is paragraph two.
Capture everything before me as this is the last sentence.
I'm using the following regex which works fine on rubular but fails in rails. Ideas why?
split(/(From:.*Date.*To:.*Subject:.*?)\n/m).first
Thank you!
Your code works as far as I tested, except that it is trailed with some "\n". If you want to remove them, add \n* to the beginning. I am not sure why you have the parentheses, and the last ? and \n. I took them off.
your_string.split(/\n*From:.*Date.*To:.*Subject:.*/m).first
Maybe using sub is more natural.
your_string.sub(/\n*From:.*Date.*To:.*Subject:.*/m, '')
You can also do this:
your_string[/.*?(?=\n*From:.*Date.*To:.*Subject:.*)/m]
Try this solution if want to extract every thing before From:
txt.gsub(/From:.*$/m, '')
The /m option makes the . match newlines.
If the word "From: " is unique,
>> s
=> "Come Find me please. This is paragraph one.\n\nThis is paragraph two. \nCapture everything before me as this is the last sentence.\n\n\n\n\nFrom: XXX XXX <xxxxx#gmail.com>\nDate: Mon, 17 May 2010 10:59:40 -0700\n\nTo: \"xxx, xxx\" <xxxxx#intuit.com>\nSubject: Re: XXXXXXXX\n\ndone"
>> s.split(/From:\s+/).first.strip
=> "Come Find me please. This is paragraph one.\n\nThis is paragraph two. \nCapture everything before me as this is the last sentence."
Is it possible to attach a marker to just a place in text, not to section, sub-section, etc.?
This is what I'm trying to achieve:
\begin{document}
Alex (see~\ref{alex}) is a boy,
Jessica (see~\ref{jessica}) is a girl.
[...]
\label{alex}\ref{alex}: Alex Johnson: 4 y.o.
\label{jessica}\ref{jessica}: Jessica D.: 5 y.o.
\end{document}
I want to get something like this:
Alex (see 1) is a boy,
Jessica (see 2) is a girl.
[...]
1: Alex Johnson: 4 y.o.
2: Jessica D.: 5 y.o.
Makes sense?
This is the solution:
\newcounter{foo}
Alex (see~\ref{alex}) is a boy,
Jessica (see~\ref{jessica}) is a girl.
[...]
\refstepcounter{foo}\thefoo\label{alex}: Alex Johnson: 4 y.o.
\refstepcounter{foo}\thefoo\label{jessica}: Jessica D.: 5 y.o.
Posted by Will at https://tex.stackexchange.com/questions/4021/how-to-set-a-marker-counter-label-to-an-arbitrary-piece-of-text
If you want to have a label, consider the following (from here);
\label{marker} You give the object you want to reference a marker, you can see it like a name.
\ref{marker} You can reference the object you have marked before. This prints the number that was assigned to the object.
\pageref{marker} It will print the number of the page where the object is.
Normally, if you reference to a label, LaTeX prints out the section, subsection, etc. But if you want to specify the exact place in text, you can use pageref. So with pageref you can exactly print out the page number of the "marker".
This is - as far as i know - the most exact possibility to tell the reader where in text a "marker" was, i.e. it is - as far as i know - impossible to tell LaTeX to print the exact line number or so.
You can use \label anywhere, including in the body of the text, but the thing labelled will be (roughly) the 'current labellable thing', that is the last \*section, or the current equation or table.
If you want to label something else (what is it you're after?) then you'll have to roll your own (not trivial), and have something which, if I recall correctly, sets \#currentlabel.
Edited, to add:
\begin{document}
\section{Hello}
Here is some text
\label{l1}
More text.
\newpage
Further text, on page 2
\label{l2}
This is section~\ref{l1} on page~\pageref{l1}.
And section~\ref{l2} on page~\pageref{l2}.
\end{document}
In both cases, the \ref refers to section 1, though the \pageref refers to pages 1 and 2 respectively. In both cases, the 'thing being labelled' is the section, and the text that goes in the label, and which appears in the \ref, is the section number.
So if you want to refer to an 'arbitrary place in the text', you have to ask yourself 'what is the text that would be produced by the \ref?'
By default (using the plain style) BibTeX orders citations alphabetically.
How to order the citations by order of appearance in the document?
There are three good answers to this question.
Use the unsrt bibliography style, if you're happy with its formatting otherwise
Use the makebst (link) tool to design your own bibliography style
And my personal recommendation:
Use the biblatex package (link). It's the most complete and flexible bibliography tool in the LaTeX world.
Using biblatex, you'd write something like
\documentclass[12pt]{article}
\usepackage[sorting=none]{biblatex}
\bibliography{journals,phd-references} % Where journals.bib and phd-references.bib are BibTeX databases
\begin{document}
\cite{robertson2007}
\cite{earnshaw1842}
\printbibliography
\end{document}
Change
\bibliographystyle{plain}
to
\bibliographystyle{ieeetr}
Then rebuild it a few times to replace the .aux and .bbl files that were made when you used the plain style.
Or simply delete the .aux and .bbl files and rebuild.
If you use MiKTeX you shouldn't need to download anything extra.
The best I came up with is using the unsrt style, which seems to be a tweaked plain style. i.e.
\bibliographystyle{unsrt}
\bibliography{bibliography}
However what if my style is not the default?
Just a brief note - I'm using a modified version of plain.bst sitting in the directory with my Latex files; it turns out having sorting by order of appearance is a relatively easy change; just find the piece of code:
...
ITERATE {presort}
SORT
...
... and comment it - I turned it to:
...
%% % avoid sort:
%% ITERATE {presort}
%%
%% SORT
...
... and then, after running bibtex, pdflatex, pdflatex - the citations will be sorted by order of appearance (that is, they will be unsorted :) ).
Cheers!
EDIT: just realized that what I wrote is actually in the comment by #ChrisN: "can you edit it to remove the SORT command" ;)
You answered your own question---unsrt is to be used when you want references to ne listed in the order of appeareance.
But you might also want to have a look at natbib, an extremely flexible citation package. I can not imagine living without it.
I'm a bit new to Bibtex (and to Latex in general) and I'd like to revive this old post since I found it came up in many of my Google search inquiries about the ordering of a bibliography in Latex.
I'm providing a more verbose answer to this question in the hope that it might help some novices out there facing the same difficulties as me.
Here is an example of the main .tex file in which the bibliography is called:
\documentclass{article}
\begin{document}
So basically this is where the body of your document goes.
``FreeBSD is easy to install,'' said no one ever \cite{drugtrafficker88}.
``Yeah well at least I've got chicken,'' said Leeroy Jenkins \cite{goodenough04}.
\newpage
\bibliographystyle{ieeetr} % Use ieeetr to list refs in the order they're cited
\bibliography{references} % Or whatever your .bib file is called
\end{document}
...and an example of the .bib file itself:
#ARTICLE{ goodenough04,
AUTHOR = "G. D. Goodenough and others",
TITLE = "What it's like to have a sick-nasty last name",
JOURNAL = "IEEE Trans. Geosci. Rem. Sens.",
YEAR = "xxxx",
volume = "xx",
number = "xx",
pages = "xx--xx"
}
#BOOK{ drugtrafficker88,
AUTHOR = "G. Drugtrafficker",
TITLE = "What it's Like to Have a Misleading Last Name",
YEAR = "xxxx",
PUBLISHER = "Harcourt Brace Jovanovich, Inc."
ADDRESS = "The Florida Alps, FL, USA"
}
Note the references in the .bib file are listed in reverse order but the references are listed in the order they are cited in the paper.
More information on the formatting of your .bib file can be found here: http://en.wikibooks.org/wiki/LaTeX/Bibliography_Management
I often use the bibliography style natbib because it supplies quite complete set of formats as well as tags for us.
Add this if you want the number of citations to appear in order in the document
they will only be unsorted in the reference page:
\bibliographystyle{unsrt}
I used the following in overleaf and become in ascending order:
\usepackage{cite}
\bibliographystyle{unsrt}
with unsrt the problem is the format. use \bibliographystyle{ieeetr} to get refences in order of citation in document.
If you happen to be using amsrefs they will override all the above - so comment out:
\usepackage{amsrefs}
The datatool package offers a nice way to sort bibliography by an arbitrary criterion, by converting it first into some database format.
Short example, taken from here and posted for the record:
\documentclass{article}
\usepackage{databib}
\begin{document}
% First argument is the name of new datatool database
% Second argument is list of .bib files
\DTLloadbbl{mybibdata}{acmtr}
% Sort database in order of year starting from most recent
\DTLsort{Year=descending}{mybibdata}
% Add citations
\nocite{*}
% Display bibliography
\DTLbibliography{mybibdata}
\end{document}
I use natbib in combination with bibliographystyle{apa}. Eg:
\begin{document}
The body of the document goes here...
\newpage
\bibliography{bibliography} % Or whatever you decided to call your .bib file
\usepackage[round, comma, sort&compress ]{natbib}
bibliographystyle{apa}
\end{document}